Skip to main content

Startup optimization library for Python 3.10+: lazy imports, speculative pre-loading, and persistent module cache.

Project description

🚀 Zenith

Startup optimization library for Python applications.

PyPI Version GitHub Repository License Python

Read this in Spanish (Español).


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

  1. Lazy Import Hook: Inserts a proxy system into sys.meta_path. import statements return a lightweight ZenithLazyModule instead of executing immediately.
  2. Speculative Pre-loader: A ThreadPoolExecutor pre-loads cached modules in background threads, bypassing the proxy system to load real modules.
  3. Persistent Cache: On exit, Zenith saves the used modules to .zenith_cache.json to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alenia_zenith-1.2.9.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alenia_zenith-1.2.9-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

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

Hashes for alenia_zenith-1.2.9.tar.gz
Algorithm Hash digest
SHA256 2d81f08be6337c29788ead9ecb895005e10f9fda264478223cfcce1f5718cddc
MD5 145f6b892397a4e6b427f7b3f303a832
BLAKE2b-256 23a97b83ba1ebd5bbb4407c7ed7633775fa02c39452356d94f284f83b0568378

See more details on using hashes here.

Provenance

The following attestation bundles were made for alenia_zenith-1.2.9.tar.gz:

Publisher: publish.yml on Kaia-Alenia/alenia-zenith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for alenia_zenith-1.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 95e64036ba7c44cfebca788aab77266dd18bb0bfe28ddf8868b602cf8072a127
MD5 ae673749e19d0da77ac776eebe4e3408
BLAKE2b-256 2a384007925e267b8ddd37d42c67af23afe6a500a406687f28c09c98bb94531b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page