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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazysafe-0.2.1.tar.gz
  • Upload date:
  • Size: 14.9 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.1.tar.gz
Algorithm Hash digest
SHA256 7c5e3596fff66bacc842d6be77f2d921798380634194209c997b88f09f93340a
MD5 311fd94b86cfbc3d533266fc146c3749
BLAKE2b-256 86b6f7869e78fc74b2ec2dea108cdb99f30859835eb7d9e73b80e88fa41dab04

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: lazysafe-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 185e56961369785492f664e48dba2d673f07333ef28dade935ad463b07b224aa
MD5 ef8726e11ded68a63f834bca5e66b16d
BLAKE2b-256 53a3f820dd56eb4025695916d9e7e05d4766db1b27f0bbf23150f645c006fd7e

See more details on using hashes here.

Provenance

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

This release

0.2.1 This release

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