Revolutionary Package CDN with Natural Import System - Stream Python packages instantly without local installation!
Project description
PyCDN - Revolutionary Package CDN with Natural Import System ๐
The Netflix of Python packages - Stream packages instantly without local installation!
PyCDN revolutionizes Python package management by serving packages through CDN networks with lazy loading and natural import syntax. Say goodbye to dependency hell and pip install delays!
๐ Revolutionary Import System
PyCDN now supports natural Python import syntax using an advanced meta path import hook system. This means you can import packages directly from CDN servers as if they were installed locally!
Classic Usage (Still Works)
import pycdn
# Connect to CDN server
cdn = pycdn.pkg("http://localhost:8000")
# Use packages via attribute access
result = cdn.math.sqrt(16) # Returns 4.0
data = cdn.numpy.array([1, 2, 3, 4, 5])
model = cdn.sklearn.LinearRegression()
๐ฏ NEW: Natural Import Syntax
import pycdn
# Connect and register CDN
cdn = pycdn.pkg("http://localhost:8000") # Registers 'cdn' prefix
# Now use natural Python imports!
from cdn.openai import OpenAI
from cdn.numpy import array, mean
from cdn.pandas import DataFrame
from cdn.sklearn.ensemble import RandomForestClassifier
# Use exactly like local packages
client = OpenAI(api_key="your-key")
data = array([1, 2, 3, 4, 5])
avg = mean(data)
df = DataFrame({"col1": [1, 2, 3]})
model = RandomForestClassifier()
๐ง Custom Import Prefixes
# Use custom prefixes for different CDN servers
ml_cdn = pycdn.pkg("http://ml-cdn:8000", prefix="ml")
data_cdn = pycdn.pkg("http://data-cdn:8000", prefix="data")
# Import from different CDNs
from ml.tensorflow import keras
from ml.pytorch import nn
from data.pandas import DataFrame
from data.dask import dataframe as dd
๐ข Multiple CDN Support
# Connect to multiple CDN environments
prod = pycdn.pkg("http://prod-cdn:8000", prefix="prod")
dev = pycdn.pkg("http://dev-cdn:8000", prefix="dev")
test = pycdn.pkg("http://test-cdn:8000", prefix="test")
# Import from specific environments
from prod.stable_package import ProductionClass
from dev.beta_package import ExperimentalFeature
from test.mock_package import TestDouble
๐ฏ Key Features
- ๐ฅ Natural Import Syntax: Use
from cdn.package import Class- feels exactly like local imports - โก Instant Access: No
pip installrequired - packages execute remotely - ๐ Global CDN: Packages served from edge locations worldwide
- ๐ Zero Dependencies: No local installation or dependency conflicts
- ๐พ Smart Caching: Intelligent caching with hybrid in-memory + disk storage
- ๐ก๏ธ Security: Sandboxed execution with runtime security scanning
- ๐ Analytics: Usage tracking and performance monitoring
- ๐ Multi-CDN: Connect to multiple CDN servers simultaneously
- ๐งฐ Development Mode: Local fallback and enhanced debugging
๐ Installation
pip install pycdn
๐ Quick Start
1. Basic Usage
import pycdn
# Connect to CDN
cdn = pycdn.pkg("http://localhost:8000")
# Classic usage
result = cdn.math.sqrt(16)
print(result) # 4.0
# Natural imports (NEW!)
from cdn.math import sqrt, pow
print(sqrt(25)) # 5.0
print(pow(2, 3)) # 8.0
2. Working with Classes
import pycdn
cdn = pycdn.pkg("http://localhost:8000")
# Import and use classes naturally
from cdn.openai import OpenAI
from cdn.sklearn.ensemble import RandomForestClassifier
# Create instances and call methods
client = OpenAI(api_key="your-key")
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello!"}]
)
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
3. Data Science Workflow
import pycdn
# Connect to data science CDN
ds_cdn = pycdn.pkg("http://ds-cdn:8000", prefix="ds")
# Natural imports for entire data pipeline
from ds.pandas import DataFrame, read_csv
from ds.numpy import array, mean, std
from ds.matplotlib.pyplot as plt
from ds.sklearn.model_selection import train_test_split
from ds.sklearn.ensemble import RandomForestRegressor
from ds.sklearn.metrics import mean_squared_error
# Use exactly like local packages
df = read_csv("data.csv")
X = df[["feature1", "feature2"]]
y = df["target"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
mse = mean_squared_error(y_test, predictions)
print(f"MSE: {mse}")
๐ ๏ธ Advanced Features
Dynamic Prefix Management
cdn = pycdn.pkg("http://localhost:8000", prefix="initial")
# Change prefix dynamically
cdn.set_prefix("dynamic")
# Enable specific package imports
cdn.enable_imports(["tensorflow", "pytorch", "scikit-learn"])
# Now these work:
from dynamic.tensorflow import keras
from dynamic.pytorch import nn
Error Handling
from pycdn import PyCDNRemoteError
try:
from cdn.nonexistent import something
except PyCDNRemoteError as e:
print(f"CDN Error: {e.message}")
print(f"Package: {e.package_name}")
if e.remote_traceback:
print(f"Remote traceback: {e.remote_traceback}")
Development Mode
# Configure for development
pycdn.configure(debug=True, timeout=60)
cdn = pycdn.pkg("http://localhost:8000", prefix="dev")
# Enables local fallback, enhanced debugging, mock mode
CDN Management
# View active CDN mappings
mappings = pycdn.get_cdn_mappings()
print(mappings) # {'cdn': 'http://localhost:8000', 'ml': 'http://ml-cdn:8000'}
# Clear all mappings
pycdn.clear_cdn_mappings()
# Register/unregister specific prefixes
pycdn.register_cdn_client("custom", cdn_client)
pycdn.unregister_cdn_client("custom")
๐๏ธ Server Setup
Deploy packages to your CDN server:
from pycdn.server import CDNServer
# Create CDN server
server = CDNServer(port=8000)
# Deploy packages
server.deploy_package("math", version="1.0.0")
server.deploy_package("numpy", version="1.24.0")
server.deploy_package("openai", version="1.0.0")
# Start server
server.start()
๐ Meta Path Import System
PyCDN uses Python's sys.meta_path to intercept imports and resolve them from CDN servers:
import sys
import pycdn
# When you create a CDN connection
cdn = pycdn.pkg("http://localhost:8000", prefix="cdn")
# PyCDN automatically:
# 1. Registers a MetaPathFinder in sys.meta_path
# 2. Maps the 'cdn' prefix to your CDN client
# 3. Intercepts imports starting with 'cdn.'
# 4. Creates proxy objects that execute remotely
# 5. Handles classes, functions, modules transparently
# All of this happens automatically!
from cdn.package import Class # Intercepted and resolved
๐ง Configuration
# Global configuration
pycdn.configure(
debug=True,
timeout=30,
cache_size="100MB",
max_retries=3
)
# Per-connection configuration
cdn = pycdn.pkg(
"http://localhost:8000",
prefix="cdn",
timeout=60,
api_key="your-api-key",
region="us-east-1",
cache_size="500MB",
max_retries=5,
debug=True
)
๐ Performance
- ๐ First call: ~50-100ms (network + execution)
- โก Cached calls: ~1-5ms (local cache hit)
- ๐พ Memory usage: Minimal (only proxy objects stored locally)
- ๐ Global reach: CDN edge servers reduce latency worldwide
- ๐ Scalability: Automatic scaling based on demand
๐ก๏ธ Security
- ๐ Sandboxed execution: Each package runs in isolated environment
- ๐ก๏ธ Runtime scanning: Real-time security vulnerability detection
- ๐ซ Package allowlists: Control which packages can be imported
- ๐ API authentication: Secure CDN access with API keys
- ๐ Audit logs: Complete execution history and monitoring
๐งช Examples
Check out our comprehensive examples:
examples/quick_import_start.py- Basic import system usageexamples/client/advanced_import_demo.py- Advanced features showcaseexamples/client/basic_usage.py- Classic PyCDN usageexamples/server/- Server deployment examples
๐ค Contributing
We welcome contributions! Check out our Contributing Guide for details.
๐ License
Apache-2.0 License - see LICENSE for details.
๐ Why PyCDN?
Traditional package management is broken:
- โ Long installation times
- โ Dependency conflicts
- โ Storage space waste
- โ Environment inconsistencies
- โ Version management complexity
PyCDN fixes all of this:
- โ Instant access - no installation needed
- โ Zero conflicts - packages run remotely
- โ Minimal storage - only proxy objects locally
- โ Consistent environments - CDN guarantees consistency
- โ Automatic updates - always use latest versions
- โ Natural syntax - import exactly like local packages
PyCDN: The Netflix of Python packages ๐ฌ
Stream packages instantly, anywhere, anytime!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycdn-1.1.6.tar.gz.
File metadata
- Download URL: pycdn-1.1.6.tar.gz
- Upload date:
- Size: 86.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b719214ccb4abf6dda824523f84803fc3c6c88109854f273a351ed6df1457854
|
|
| MD5 |
0e86f4812af7e61756c11ab87ddfbfe9
|
|
| BLAKE2b-256 |
b4770a8e504df0f4a3dd977b22d1aea6c85164300911dfdc1bdb00ab82b672ed
|
File details
Details for the file pycdn-1.1.6-py3-none-any.whl.
File metadata
- Download URL: pycdn-1.1.6-py3-none-any.whl
- Upload date:
- Size: 50.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e181254b3d0996bec6b246e284322f32eca3c34c6f967e8e20e60cba9bae91e
|
|
| MD5 |
221372767fd878724b8fc527a5a0eed3
|
|
| BLAKE2b-256 |
40b305a3990c0543eeb4da155660d4fcecb3d64c7fe38e1013052fcb232dd62c
|