Skip to main content

lazysafe

safely adopt python 3.15 lazy imports.

why it exists

python 3.15 ships PEP 810 explicit lazy imports. lazy import json defers loading until first use. reported wins: ~2.9x faster startup for import-heavy applications.

the catch: laziness changes when import-time side effects run. some libraries depend on them. under lazy mode, programs break in confusing ways.

lazysafe answers that question empirically.

install

pip install lazysafe

quickstart

# see which imports are safe to make lazy
lazysafe analyze src/

# show all modules including safe ones
lazysafe analyze src/ --all

# measure startup time
lazysafe measure python -m myapp --budget 500

# probe modules for runtime side effects
lazysafe probe requests flask yaml

what it does

lazysafe scans your Python source files and classifies every import statement by its side-effect risk:

finding meaning action
SAFE no side effects detected safe to make lazy
RISKY might have side effects investigate before lazy
UNSAFE side effect detected keep eager
UNKNOWN can't determine statically needs further investigation

side-effect rules

code what it detects confidence
SE01 module-level function calls 0.6
SE02 foreign attribute assignment (monkeypatching) 0.9
SE03 sys.path / sys.modules / os.environ mutation 0.95
SE04 atexit / signal / logging registration 0.85-0.9
SE05 module-level file I/O 0.8
SE06 framework registration decorators (2+) 0.5
SE07 importlib.import_module with computed names 0.9
SE08 try/except ImportError with fallback patches 0.7

what it does not do

  • runtime lazy-loading for older pythons (no backport of PEP 810)
  • patching third-party packages' code
  • general linting/formatting (use ruff)

requirements

  • python >= 3.11 (host running lazysafe)
  • target programs using lazy import semantics require python >= 3.15
  • linux, macos, windows

links

license

MIT

Download files

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

Source Distribution

lazysafe-0.3.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

lazysafe-0.3.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file lazysafe-0.3.0.tar.gz.

File metadata

  • Download URL: lazysafe-0.3.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lazysafe-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3d963a6fd410b3aa49e5cd3cbf61c526d6bff0d38d4045ab5ded20c8c5228a11
MD5 2ba74590b0a88183cc77f9384c7f0018
BLAKE2b-256 60581fc41d1e8173863479d3570d3e48f11172c21dacb7b581ccbb733593ef80

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazysafe-0.3.0.tar.gz:

Publisher: release.yml on rahulXs/lazysafe

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

File details

Details for the file lazysafe-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lazysafe-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lazysafe-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a6c533fdc097f46184e7f68f107482e61691135d67b6236902636faa5d6e47c
MD5 99511bca21ef8a698e8a104dfe847967
BLAKE2b-256 f924a274f406ae9fce458be8332e13867e19461a8be0f03a7a366472120ba988

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazysafe-0.3.0-py3-none-any.whl:

Publisher: release.yml on rahulXs/lazysafe

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

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 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