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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa6b13f42a7d16980b0261c2ea07bc4e08bf53b2acc498eeda36a31c8fac20f4
|
|
| MD5 |
e56e620512ee5fb565254c705e08caff
|
|
| BLAKE2b-256 |
14543d3364b75fa628d04634e85db9b5301e0e7d18d58ab29f07679d181bdc52
|
Provenance
The following attestation bundles were made for lazysafe-0.2.0.tar.gz:
Publisher:
release.yml on rahulXs/lazysafe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazysafe-0.2.0.tar.gz -
Subject digest:
fa6b13f42a7d16980b0261c2ea07bc4e08bf53b2acc498eeda36a31c8fac20f4 - Sigstore transparency entry: 2771000180
- Sigstore integration time:
-
Permalink:
rahulXs/lazysafe@bd04c5888fe4aa45f89cf1fb00318a3c82ec75a7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/rahulXs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bd04c5888fe4aa45f89cf1fb00318a3c82ec75a7 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
538abc821c68a5d34533f16b0a207844607b1a9e9d4be9a63bae00683820ee66
|
|
| MD5 |
cd2adc7cbc11d8d95e361621734cb107
|
|
| BLAKE2b-256 |
820377e8aa99473a07a58161707d5c2e432ec7b152e402296b0d1ac9dce955af
|
Provenance
The following attestation bundles were made for lazysafe-0.2.0-py3-none-any.whl:
Publisher:
release.yml on rahulXs/lazysafe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lazysafe-0.2.0-py3-none-any.whl -
Subject digest:
538abc821c68a5d34533f16b0a207844607b1a9e9d4be9a63bae00683820ee66 - Sigstore transparency entry: 2771000275
- Sigstore integration time:
-
Permalink:
rahulXs/lazysafe@bd04c5888fe4aa45f89cf1fb00318a3c82ec75a7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/rahulXs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bd04c5888fe4aa45f89cf1fb00318a3c82ec75a7 -
Trigger Event:
push
-
Statement type: