Skip to content

Repository files navigation

🔥 Load - Modern Python Import Alternative

Load is a modern alternative to Python's import system, inspired by the simplicity of Go and Groovy. It provides automatic package installation, intelligent caching, and magic import syntax.

🎯 Purpose

Load simplifies Python imports by:

  • Reducing boilerplate code
  • Automating package installation
  • Improving developer productivity
  • Making imports more intuitive

✨ Features

  • Automatic Package Installation: Missing packages are installed on demand
  • Smart Caching: Modules are cached for faster subsequent imports
  • Magic Import Syntax: Import with just the package name
  • Function-level Imports: Use @load decorator to manage dependencies at function level
  • Multiple Registries: Support for PyPI, GitHub, GitLab, and private registries
  • Python 2/3 Compatible: Works across Python versions

🚀 Quick Start

Install load using any of these methods:

# 1. Using curl (Linux/macOS/WSL)
curl -sSL https://load.pyfunc.com | python3 -
# 2. Using PowerShell (Windows)
(Invoke-WebRequest -Uri https://load.pyfunc.com -UseBasicParsing).Content | py -
# 3. Using Poetry
poetry add load
# 4. Using pip
pip install load

📚 Documentation

For detailed documentation, please refer to:

🎯 Function-level Dependency Loading

Use the @load decorator to automatically handle dependencies for specific functions:

fromloadimportload_decoratorasload@load('numpy', 'pandas', 'plt=matplotlib.pyplot')defanalyze_data():
importnumpyasnpdata=np.random.rand(10, 3)
plt.plot(data)
plt.show()
# The required packages will be automatically installed when the function is first calledanalyze_data()

For more examples and advanced usage, see the Decorator Documentation.

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

📚 Documentation Index

🔗 Links

🔍 Real-World Example

Data Science Workflow

# Traditional wayimportnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportseabornassnsfromsklearn.linear_modelimportLinearRegression# With Loadfromloadimportload, import_aliases# Single importnp=load('numpy')
# Multiple imports with aliasespd, plt, sns=import_aliases('pandas', 'plt=matplotlib.pyplot', 'seaborn')
# Direct attribute accessmodel=load('sklearn.linear_model.LinearRegression')()
# Now use them as usualdata=pd.DataFrame({'x': [1, 2, 3], 'y': [1, 2, 3]})
model.fit(data[['x']], data['y'])
plt.scatter(data['x'], data['y'])
plt.plot(data['x'], model.predict(data[['x']]), 'r')
plt.show()

Web Development

fromloadimportload, configure_private_registry# Configure private registryconfigure_private_registry(
name="company",
index_url="https://pypi.company.com/simple/"
)
# Import standard and private packagesfastapi=load('fastapi')
internal_auth=load('company-auth', registry="company")
app=fastapi.FastAPI()
@app.get("/")asyncdefroot():
return {"message": "Hello World"}

🔒 Prywatne rejestry

# Prywatny PyPI firmyconfigure_private_registry(
name="company",
index_url="https://pypi.company.com/simple/"
)
# Prywatny GitLab z tokenem configure_private_registry(
name="internal", base_url="https://gitlab.company.com/",
token="your-token"# lub GITLAB_TOKEN env var
)
# Użyjcompany_lib=load("internal-package", registry="company")
secret_tool=load("team/secret-sauce", registry="internal")

🎯 Smart Loading - automatyczne wykrywanie

Load automatycznie wykrywa skąd ładować:

load("json") # → stdlib (nie instaluje)load("requests") # → PyPI load("user/repo") # → GitHubload("gitlab.com/user/proj") # → GitLabload("./file.py") # → Lokalny plikload("https://example.com/x.py") # → URL

🏢 Przykłady dla firm

Startup z GitHub

# Najnowsze z GitHub zamiast PyPIml_lib=load("huggingface/transformers")
selenium=load("SeleniumHQ/selenium/py") playwright=load("microsoft/playwright-python")

Korporacja z prywatnymi rejestrami

# Skonfiguruj rejestry firmyconfigure_private_registry("nexus", index_url="https://nexus.company.com/pypi/simple/")
configure_private_registry("artifactory",
index_url="https://company.jfrog.io/pypi/simple/")
# Używajauth_lib=load("company-auth", registry="nexus")
internal_api=load("team-api-client", registry="artifactory")

Projekt z mieszanymi źródłami

defsetup_project():
return {
# PyPI - stabilne wersje'web': load("fastapi"),
'db': load("sqlalchemy"),
# GitHub - najnowsze funkcje 'ai': load("openai/openai-python"),
'scraping': load("microsoft/playwright-python"),
# Prywatne - firmowe narzędzia'auth': load("auth-service", registry="company"),
'monitoring': load("team/observability", registry="internal"),
# Lokalne - logika biznesowa'models': load("./models.py"),
'utils': load("./utils.py")
}

🔧 Zarządzanie rejestrami

# Lista dostępnych rejestrówlist_registries()
# Dodaj własny rejestradd_registry("custom", {
'index_url': 'https://pypi.custom.com/simple/',
'install_cmd': [sys.executable, "-m", "pip", "install", "--index-url"],
'description': 'Custom PyPI mirror'
})
# Szybka konfiguracjaconfigure_private_registry("maven-central", index_url="https://maven.central.com/pypi/")

🚀 Przykłady projektów

Data Science

defsetup_ds():
return {
'pd': load("pandas", "pd"), # PyPI'np': load("numpy", "np"), # PyPI 'latest_sklearn': load("scikit-learn/scikit-learn"), # GitHub'utils': load("./ds_utils.py") # Local
}

Web Development

defsetup_web():
return {
'api': load("fastapi"), # PyPI'auth': load("company-sso", registry="nexus"), # Private'monitoring': load("team/apm-client", registry="gitlab"), # GitLab'models': load("./models.py") # Local
}

AI/ML Pipeline

defsetup_ai():
return {
'torch': load("pytorch/pytorch"), # GitHub latest'transformers': load("huggingface/transformers"), # GitHub'custom_models': load("team/ml-models", registry="company"), # Private'preprocessing': load("./preprocess.py") # Local
}

📊 Popularne rejestry w praktyce

Dla startupów

  • PyPI - podstawowe biblioteki
  • GitHub - najnowsze wersje, eksperymenty
  • Lokalne pliki - własna logika

Dla korporacji

  • PyPI - sprawdzone, stable biblioteki
  • Prywatny PyPI - firmowe pakiety
  • GitLab Enterprise - internal repos
  • Artifactory/Nexus - cache i security scanning

Dla research

  • GitHub - cutting-edge research code
  • PyPI - etablowane biblioteki naukowe
  • URL - papers with code, direct downloads

🔒 Bezpieczeństwo

# Kontroluj źródłaALLOWED_REGISTRIES= ['pypi', 'company', 'github-trusted']
defsecure_load(name, registry=None):
ifregistrynotinALLOWED_REGISTRIES:
raiseSecurityError(f"Registry {registry} not allowed")
returnload(name, registry=registry)

🎉 Dlaczego Load?

ProblemTradycyjnieZ Load
Instalacjapip install pkgload("pkg")
GitHub repoClone, setup.py, pip installload("user/repo")
Prywatny rejestrKonfiguruj pip.confload("pkg", registry="company")
Różne źródłaRóżne komendyload() dla wszystkiego
Najnowsza wersjaCzekaj na PyPIload("user/repo") z GitHub

Load - jeden interfejs do wszystkich rejestrów Python! 🚀


Skopiuj load.py, napisz from load import * i ładuj skąd chcesz!

🔥 Podsumowanie - Load z rejestrami

Load z obsługą wszystkich głównych rejestrów Python:

📦 Obsługiwane rejestry:

  1. PyPI (~500k pakietów) - load("requests")
  2. GitHub (~miliony repozytoriów) - load("user/repo")
  3. GitLab (~setki tysięcy) - load("gitlab.com/user/proj")
  4. Prywatne PyPI - load("pkg", registry="company")
  5. URL - load("https://example.com/lib.py")
  6. Lokalne pliki - load("./utils.py")

🚀 Kluczowe funkcje:

  • Smart detection - automatycznie wykrywa skąd ładować
  • Auto-install - instaluje co brakuje
  • Cache w RAM - szybkie powtórne ładowanie
  • Prywatne rejestry - obsługa firmowych PyPI/GitLab z tokenami
  • Zero config - działa od razu

💪 Użycie:

fromloadimport*# Podstawowehttp=requests() # PyPIdata=pd() # PyPI + alias# GitHub (najnowsze wersje)ai=load("openai/openai-python") # GitHubml=load("huggingface/transformers") # GitHub# Prywatne firmyauth=load("company-auth", registry="nexus")
api=load("team/api", registry="gitlab")
# Lokalneutils=load("./utils.py")

🏢 Dla firm:

# Skonfiguruj razconfigure_private_registry("company", index_url="https://pypi.company.com/simple/")
# Używaj wszędzieinternal_lib=load("secret-package", registry="company")

🎯 Główne zalety:

  1. Jeden interfejs do wszystkich źródeł
  2. Automatyczne wykrywanie - nie musisz pamiętać skąd co
  3. Obsługa tokenów dla prywatnych repozytoriów
  4. Szybkie dzięki cache w RAM
  5. Proste jak w Go - jedna funkcja load()

Rezultat: Zamiast kombinować z pip install, git clone, konfiguracją pip.conf - po prostu load() i działa! 🚀

About

load alternatywa dla import w Pythonie, inspirowaną prostotą Go i Groovy.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages