Skip to main content

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 install required - 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:

🤝 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!

Release files for pycdn 1.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycdn 1.1.7
File Size Uploaded
pycdn-1.1.7.tar.gz 87.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycdn 1.1.7
File Interpreter ABI Platform
pycdn-1.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 137.4 kB

Release files / pycdn-1.1.7.tar.gz

Download URL pycdn-1.1.7.tar.gz
Size 87.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fb031ec53325a6dfff82cf46931b4d4d675ad71e5446a857d84b303b12108d3b
BLAKE2b-256 checksum
How to use checksums
3afde9c094cfadc5c936607bad8c18fac880025a30f39b0aa029a3b5a57b6c81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / pycdn-1.1.7-py3-none-any.whl

Download URL pycdn-1.1.7-py3-none-any.whl
Size 50.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cf51cad9fd742331a545196a39bf495e85a14b1fb12e0b8fd0beafd6cafa5f1
BLAKE2b-256 checksum
How to use checksums
6b61e9b626d7ec052b70da19bd149b51daa0ab6813b26f5568214c60199d3b5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.1.7 This release

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page