Skip to main content

cdk-lazy-import

Speed up AWS CDK synth in Python by lazy-loading aws_cdk.aws_* service modules.

The problem

The AWS CDK for Python uses jsii to bridge between JavaScript and Python. When you import aws_cdk.aws_s3, jsii eagerly loads the module and all of its dependencies. A typical CDK app imports a handful of service modules, but each one pulls in shared machinery that touches all ~300 service packages. This means cdk synth spends several seconds just on imports before it even starts synthesizing your stack.

How it works

cdk-lazy-import installs a meta path finder that intercepts import aws_cdk.aws_* statements. Instead of loading the real module immediately, it returns a lightweight stub. The stub defers all work until your code actually accesses an attribute (like aws_s3.Bucket), at which point the real module is loaded transparently.

Non-service submodules (aws_cdk.cx_api, aws_cdk.pipelines, aws_cdk._jsii, etc.) are not intercepted and load normally. Deeper imports like aws_cdk.aws_s3.notifications are also handled normally once their parent resolves.

The result is byte-identical CloudFormation output with ~30-40% faster synth times in limited testing (~5.8s vs ~9.0s).

Installation

pip install cdk-lazy-import

That's it. The package includes a .pth file that activates the lazy-loading hook automatically at interpreter startup. No code changes, no configuration, no manual imports.

If aws-cdk-lib is not installed in the environment, the hook is a silent no-op.

Uninstallation

pip uninstall cdk-lazy-import

Removing the package removes the .pth file and restores default import behavior.

API

For most users, installing the package is sufficient. If you need manual control:

import cdk_lazy_import

# The .pth file calls this automatically, but you can call it yourself
# if you need to install the hook at a specific point. It's a no-op if
# the hook is already installed or aws_cdk is not available.
cdk_lazy_import.install()

Caveats

  • Only aws_cdk.aws_* submodules are lazified. Other submodules load normally.
  • The hook must be installed before any aws_cdk.aws_* imports. The .pth file ensures this happens at interpreter startup, but if something imports CDK modules before .pth files are processed (unusual), those modules won't be lazified.
  • Performance gains depend on how many service modules your app uses. Apps that import nearly every service module will see less benefit.

Metadata

Release files for cdk-lazy-import 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-lazy-import 1.0.0
File Size Uploaded
cdk_lazy_import-1.0.0.tar.gz 53.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cdk-lazy-import 1.0.0
File Interpreter ABI Platform
cdk_lazy_import-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.5 kB

Release files / cdk_lazy_import-1.0.0.tar.gz

Download URL cdk_lazy_import-1.0.0.tar.gz
Size 53.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ee21929c779c1f10735c3997b4a04716fdbcc6b7d0c0618306b1f55268dda2ea
BLAKE2b-256 checksum
How to use checksums
6b4daf2f256227efa5db514d70718955a89735503b5013ae05ed838a416a01dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Apr 5, 2026.

Transparency log

Release files / cdk_lazy_import-1.0.0-py3-none-any.whl

Download URL cdk_lazy_import-1.0.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6416e72ecc4addda60c37f733644bd30dc2c6c2a120ea3ed5029e6a3ffc8d6f
BLAKE2b-256 checksum
How to use checksums
63e3f420755695f712d03b85d3ad1511d756d73bbcb4964145704e5d4b26ee63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Apr 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release 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