Skip to main content

Build focused Python Lambda pack bundles from source imports.

Project description

monopack

monopack splits a Python monorepo into smaller, entrypoint-focused packages.

Packs are defined by files in packs/ (packs/<name>.py). For each pack, monopack traces imports, copies reachable first-party files, installs only the needed third-party distributions, and writes an isolated build output.

If packs/ is missing, or no pack files are found, the CLI exits with a clear error.

Background

This was inspired by multi-function Lambda packaging, where smaller per-entrypoint artifacts often help cold start performance and reduce package bloat. The same approach works for any Python monorepo where you want tighter per-entrypoint packaging.

Why use it

  • Smaller per-pack artifacts from one shared codebase.
  • Tighter dependency surface for each pack.
  • Easier to inspect what each entrypoint actually ships.

Basic usage

Build one pack:

python -m monopack users_get

Build all discovered packs in packs/*.py:

python -m monopack

Run test-mode build for one pack:

python -m monopack users_get --mode test

Deploy-mode build with test gate:

python -m monopack users_get --mode deploy --with-tests

Verify and test mode

  • --verify (default on): runs a generated verifier script inside the built pack to check importability of selected modules and validate pack entrypoint expectations (including lambda_handler on the pack module).
  • --mode test: builds the runtime payload, copies only relevant tests for that pack, runs them inside the build target, and does not write a deploy zip.
  • --with-tests: same test execution behavior as above, but in deploy mode so zip output is still produced if checks pass.

tests/ is required only when test execution is enabled (--mode test or --with-tests).

CLI options

Command form:

python -m monopack [pack_name] [options]
Option Default Why it is useful
pack_name (positional, optional) builds all discovered packs Target a single pack while iterating locally or in CI.
--version n/a Print installed CLI version and exit.
--packs-dir packs Use a non-default entrypoint directory.
--build-dir build Change output location (for CI temp dirs or custom build roots).
--mode deploy|test deploy deploy produces runtime payload + zip, test runs pack-scoped tests in build output (no zip).
--with-tests False Run pack-scoped tests as a gate in deploy mode.
--verify / --no-verify verify on Keep safety checks on by default; disable for faster local loops.
--auto-fix False Retry missing-module verification failures by updating managed inline config blocks (up to 3 attempts).
--debug False Print detailed import and dependency resolution diagnostics to stderr.
--jobs auto Parallelize multi-pack builds; set a number for fixed worker count.
--sha-output hex Choose deploy digest output format(s): hex, b64, or hex,b64.
--package-manager auto Select dependency source flow: auto, pip, uv, poetry, pipenv.
--existing-install-python unset Point to an existing Python install to reuse pip cache artifacts during dependency cache sync.

Environment variables are also supported. CLI flags override env vars.

How it works

  1. Resolve target packs from packs/ or explicit pack_name.
  2. Build an import graph from each pack entrypoint.
  3. Copy reachable first-party files into build/<pack_name>/.
  4. Resolve third-party import roots to distributions from pinned dependency sync.
  5. Install only that per-pack dependency subset into the build target.
  6. Run verifier and optional pack-scoped tests.
  7. In deploy mode, write zip artifact and optional digest files.

More docs

  • CLI reference: docs/cli.md
  • Fixture-driven testing notes: docs/testing-fixtures.md
  • Publishing: docs/publishing.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monopack-0.3.2.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monopack-0.3.2-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file monopack-0.3.2.tar.gz.

File metadata

  • Download URL: monopack-0.3.2.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for monopack-0.3.2.tar.gz
Algorithm Hash digest
SHA256 148ff4194d011194041a15531688e86f32ef932da1ff837de2b41720c2a97fb6
MD5 2b764a1862db8659e4beeaf237021747
BLAKE2b-256 7328ef1d5c1bf29741cfbd47909fdbafaf15d8b509d789be030b1ce13a3862c5

See more details on using hashes here.

File details

Details for the file monopack-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: monopack-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for monopack-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d72e7e76390e51cc1d407b6800f94b1f8f382c7b5207b11550677de61fc6943
MD5 a6fb54cd55831b196e9eed7b5b6e9abf
BLAKE2b-256 1c56c904dc0afe6c45ff8a45e63f85c69e9de6326795f4722b2dc1fe5841b272

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page