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

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.2.0.tar.gz (14.0 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.2.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lazysafe-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fa6b13f42a7d16980b0261c2ea07bc4e08bf53b2acc498eeda36a31c8fac20f4
MD5 e56e620512ee5fb565254c705e08caff
BLAKE2b-256 14543d3364b75fa628d04634e85db9b5301e0e7d18d58ab29f07679d181bdc52

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazysafe-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: lazysafe-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 538abc821c68a5d34533f16b0a207844607b1a9e9d4be9a63bae00683820ee66
MD5 cd2adc7cbc11d8d95e361621734cb107
BLAKE2b-256 820377e8aa99473a07a58161707d5c2e432ec7b152e402296b0d1ac9dce955af

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazysafe-0.2.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

0.3.0

2 files

0.2.1

2 files

This release

0.2.0 This release

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