Skip to main content

A dead-simple, zero-dependency lazy import proxy to make Python CLIs start instantly.

Project description

cli-speeder

Make your Python CLIs start instantly (10x-100x faster). Python scripts are notoriously slow to start because they import heavy libraries (like pandas, torch, boto3, pydantic) at the top level, even if the user only runs a simple command like --help.

cli-speeder fixes this with zero code refactoring.

Installation

pip install cli-speeder

Usage

There are two ways to use this.

Method 1: The "One-Liner" (Recommended)

Add this once at the very top of your script (before your heavy imports).

from cli_speeder import speed_up_modules
# Magic: Forces these modules to load lazily
speed_up_modules(["pandas", "tensorflow", "boto3"])

# --- Your normal code stays exactly the same! ---
import pandas as pd      \# 0ms (Instant)
import tensorflow as tf  \# 0ms (Instant)
import boto3             \# 0ms (Instant)

def process_data():
\# The libraries only actually load HERE, when you use them.
df = pd.read_csv("data.csv")

Method 2: Manual Proxy (Granular Control)

If you want specific control over exactly which object is lazy.

from cli_speeder import lazy_import, lazy_from_import

# Replace 'import pandas as pd' with:
pd = lazy_import("pandas")

# Replace 'from pandas import DataFrame' with:
DataFrame = lazy_from_import("pandas", "DataFrame")

Benchmarks

Time to run python script.py --help:

Library Standard Import With cli-speeder
Pandas ~0.8s < 0.01s
Torch ~2.5s < 0.01s
Boto3 ~0.5s < 0.01s

Debugging / Production Safety

Lazy loading is great for CLIs, but sometimes (like in production workers) you might want standard behavior to catch ImportError immediately.

You can force all imports to happen immediately (disable lazy loading) by setting an environment variable:

export CLI_SPEEDER_EAGER=1
python my_script.py

License

cli_speeder is licensed under the Apache License 2.0. See the LICENSE file for more details.

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

cli_speeder-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

cli_speeder-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cli_speeder-0.1.1.tar.gz.

File metadata

  • Download URL: cli_speeder-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cli_speeder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5d86ac7b529b0447bfb1d77e7f6ff8a29e35386ce38c8a3a6503d066733415fc
MD5 e6c1a7dac84b7925b428345a0d4efeee
BLAKE2b-256 95d78eac54916c8a24e7412ced6fe15ae8b782c98200882015f9c86cf3d10ce2

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_speeder-0.1.1.tar.gz:

Publisher: publish.yml on Nabarup1/cli_speeder

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

File details

Details for the file cli_speeder-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cli_speeder-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cli_speeder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf202f5fa50633aa7d704940ea51d0c3be68db1ccb1963dd216051d175b187e
MD5 a0c8bb30122b58f5a853b2c2b0e0e0b2
BLAKE2b-256 a968adc79bf723a67d72149d33828c343cb0f8c0efc114c9d681cae2574c6425

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_speeder-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Nabarup1/cli_speeder

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