lazyexport
Lazy package exports from ordinary import declarations. Extracted from AnyIO's lazy importer, under its MIT license. Requires Python 3.11 or later and has no runtime dependencies.
from typing import TYPE_CHECKING
from lazyexport import install, fix_package_names
if TYPE_CHECKING or not install():
from ._client import Client as Client
fix_package_names()
Place this in your package's __init__.py (ordinary modules also work).
install() reads the calling module's source and builds a map of exports from
the imports in the conditional block. It installs module-level __getattr__
and __dir__ hooks and returns True, skipping the eager imports. Accessing an
export imports its implementation and caches the value in the calling module.
If source is unavailable, it returns False and the imports execute eagerly.
fix_package_names() makes implementation module names public in that fallback.
The lazy path also rewrites exported objects' __module__ to the exporting module.
Supported declarations
Use direct from module import name statements inside the top-level
if TYPE_CHECKING or not install(): block. Relative imports and export aliases
are supported. from . import submodule exposes submodules lazily. Star imports,
plain import module declarations, and nested import declarations are unsupported.
Use the unaliased helper names shown here.
For deprecated names, import set_deprecated_aliases from lazyexport and call it
inside the block with a literal dictionary mapping old names to fully qualified
replacement names. Access emits DeprecationWarning. Lazy resolutions are cached;
the eager fallback warns on each access.
The installer replaces existing __getattr__ and __dir__ hooks. dir() lists
mapped attribute exports. Define __all__ explicitly if you need star exports;
star importing resolves those exports eagerly. References to missing names inside
the exporting module do not trigger __getattr__; use this for exports consumed
through module attribute access or from imports.
Development
python -m pip install --upgrade pip
python -m pip install --group dev -e .
python -m pytest
Releasing
Add a fragment in changelog.d/ for each user-facing change; see
changelog.d/README.rst for naming and types.
Set project.version in pyproject.toml to the release version, then preview
and generate the changelog (using that same version):
uv run --group dev towncrier build --draft --version 0.1.0
uv run --group dev towncrier build --yes --version 0.1.0
Commit the version update, generated CHANGELOG.rst, and deleted fragments.
Push the commit, then push a matching version tag:
git tag 0.1.0
git push origin 0.1.0
The release workflow tests the package, builds and checks the wheel and source
distribution, and publishes them to PyPI using trusted publishing. The tag must
match the package version exactly (no v prefix). Configure the PyPI trusted
publisher with this repository and workflow filename release.yml, leaving the
environment field empty. No API token is required.
Metadata
Release files for lazyexport 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lazyexport-0.1.1.tar.gz | 5.2 kB | With provenance | Details for lazyexport-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lazyexport-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for lazyexport-0.1.1-py3-none-any.whl |
Total release size: 10.9 kB
Release files / lazyexport-0.1.1.tar.gz
| Download URL | lazyexport-0.1.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76401fe9f2733d4ac6a7223ace52c8f9b8770b05c0642835660a8980eb87fa67
|
|
BLAKE2b-256 checksum How to use checksums |
22ed9aeb71b346ab3a47c67e6bc0dea4910fa86b35de70fef27ffe2aa1950adc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / lazyexport-0.1.1-py3-none-any.whl
| Download URL | lazyexport-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6544cb7336a6fbfaa62d80f5bc94553a7f3a5f1f7ade64af677b8d65bba411b0
|
|
BLAKE2b-256 checksum How to use checksums |
1761386f2b84bd1b57436fd7aeef8a5f0b5227f8f61b694af04b0217d88b5e73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for lazyexport 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for lazyexport-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.