Startup optimization library for Python 3.10+: lazy imports, speculative pre-loading, and persistent module cache.
Project description
Zenith reduces your application's import time by combining lazy import proxies (modules are not executed until first attribute access) and speculative background pre-loading (a thread pool pre-loads known modules while your app boots). A persistent cache learns which modules your app uses across runs, making every subsequent boot faster.
Why Zenith? Python 3.15 introduces lazy imports, but Zenith actively pre-loads modules in the background based on run history, so they are ready before you access them.
✨ Key Features & Use Cases
- ⚡ Command Line Interfaces (CLIs): Deliver sub-second launch times for tools where a startup latency of 200ms+ ruins user experience.
- ☁️ Serverless APIs (Cold Starts): Drastically reduce cold starts in serverless environments (AWS Lambda, Google Cloud Run) by allowing the server to bind and listen immediately.
- 📊 Data Science & ML Pipelines: Bypass the initialization lag of heavy packages (
pandas,numpy,torch) during frequent script executions. - 🖥️ Desktop / GUI Applications: Improve perceived performance by launching the main interface instantly while loading secondary libraries asynchronously.
📈 Benchmarks
Benchmarks run on isolated subprocesses (5 runs averaged) loading heavy standard and third-party libraries:
| Metric | Native Python | Zenith (warm) | Improvement |
|---|---|---|---|
| Avg Boot (ms) | ~52ms | ~37ms | ~28% 🚀 |
(Note: First run builds the cache. Subsequent runs benefit from speculative pre-loading. Results vary by hardware and module set.)
🛠️ Installation
pip install alenia-zenith
For system-wide use (Docker, CI/CD), append --break-system-packages.
🚀 Quick Start
Initialize Zenith at the very top of your application entrypoint:
import zenith
zenith.ignite()
# Your imports — served lazily and pre-loaded in the background
import pandas as pd
import numpy as np
import requests
Advanced Initialization
import zenith
zenith.ignite(
file=__file__, # Scan this file's imports and pre-load them
workers=8, # Background thread pool size (default: 4)
verbose=True, # Print pre-load events to stdout
exclude=["mymodule", "django"], # Never lazy-load these packages
cache_path=".cache/zenith.json", # Custom cache location
show_banner=False, # Suppress the ASCII banner
)
# Explicitly pre-load specific modules
zenith.warm("pandas", "numpy", "torch")
⚙️ How It Works
- Lazy Import Hook: Inserts a proxy system into
sys.meta_path.importstatements return a lightweightZenithLazyModuleinstead of executing immediately. - Speculative Pre-loader: A
ThreadPoolExecutorpre-loads cached modules in background threads, bypassing the proxy system to load real modules. - Persistent Cache: On exit, Zenith saves the used modules to
.zenith_cache.jsonto accelerate future executions.
💻 CLI Tools
Zenith provides a built-in CLI for diagnostics and benchmarking:
# Analyze imports in a file
zenith analyze myapp/main.py --verbose
# Show cache status
zenith status
# Run a benchmark comparison
zenith benchmark --runs 5 --modules pandas numpy requests
# Clear the cache
zenith invalidate
⚠️ Known Limitations
- GIL: Zenith uses standard threading. Background threads share the GIL with the main thread, making pre-loading concurrent, not parallel. Speedups come from overlapping I/O-bound disk reads.
- Cold First Run: The first run has no cache and shows no speedup. The magic happens from the second run onward.
- C Extensions: Some C extension modules are not safe to import from a background thread. Use
zenith.exclude("module_name")for those.
📜 License
Distributed under the GNU General Public License v3 (GPL v3). See LICENSE for more information.
Contact: contact.aleniastudios@gmail.com
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 alenia_zenith-1.2.9.tar.gz.
File metadata
- Download URL: alenia_zenith-1.2.9.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d81f08be6337c29788ead9ecb895005e10f9fda264478223cfcce1f5718cddc
|
|
| MD5 |
145f6b892397a4e6b427f7b3f303a832
|
|
| BLAKE2b-256 |
23a97b83ba1ebd5bbb4407c7ed7633775fa02c39452356d94f284f83b0568378
|
Provenance
The following attestation bundles were made for alenia_zenith-1.2.9.tar.gz:
Publisher:
publish.yml on Kaia-Alenia/alenia-zenith
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alenia_zenith-1.2.9.tar.gz -
Subject digest:
2d81f08be6337c29788ead9ecb895005e10f9fda264478223cfcce1f5718cddc - Sigstore transparency entry: 2043617614
- Sigstore integration time:
-
Permalink:
Kaia-Alenia/alenia-zenith@eeae1c0b77e552472780af49bccb9dbd2f167bd0 -
Branch / Tag:
refs/tags/v1.2.9 - Owner: https://github.com/Kaia-Alenia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eeae1c0b77e552472780af49bccb9dbd2f167bd0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file alenia_zenith-1.2.9-py3-none-any.whl.
File metadata
- Download URL: alenia_zenith-1.2.9-py3-none-any.whl
- Upload date:
- Size: 26.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e64036ba7c44cfebca788aab77266dd18bb0bfe28ddf8868b602cf8072a127
|
|
| MD5 |
ae673749e19d0da77ac776eebe4e3408
|
|
| BLAKE2b-256 |
2a384007925e267b8ddd37d42c67af23afe6a500a406687f28c09c98bb94531b
|
Provenance
The following attestation bundles were made for alenia_zenith-1.2.9-py3-none-any.whl:
Publisher:
publish.yml on Kaia-Alenia/alenia-zenith
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alenia_zenith-1.2.9-py3-none-any.whl -
Subject digest:
95e64036ba7c44cfebca788aab77266dd18bb0bfe28ddf8868b602cf8072a127 - Sigstore transparency entry: 2043617635
- Sigstore integration time:
-
Permalink:
Kaia-Alenia/alenia-zenith@eeae1c0b77e552472780af49bccb9dbd2f167bd0 -
Branch / Tag:
refs/tags/v1.2.9 - Owner: https://github.com/Kaia-Alenia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@eeae1c0b77e552472780af49bccb9dbd2f167bd0 -
Trigger Event:
push
-
Statement type: