Skip to main content

Monkay

Monkay is a production-focused module lifecycle toolkit for Python packages. It helps you ship lazy imports, settings loading, extension orchestration, and context-isolated state without fragile import-time side effects.

Why Monkay

Monkay is designed for libraries and applications that need to:

  • expose stable public imports while deferring expensive imports,
  • run controlled startup preloads and settings evaluation,
  • apply pluggable extensions with deterministic conflict behavior,
  • isolate mutable state per thread/task for safe tests and request scopes,
  • validate module export consistency during development.

Installation

pip install monkay

Runtime requirement: Python 3.10+.

60-Second Example

# yourpkg/__init__.py
from monkay import Monkay

monkay = Monkay(
    globals(),
    lazy_imports={
        "json_dumps": "json:dumps",
    },
)

__all__ = ["json_dumps", "monkay"]
# yourpkg/main.py
from yourpkg import json_dumps

payload = {"status": "ok"}
print(json_dumps(payload))

json_dumps is resolved lazily on first access and cached by default.

Core Capabilities

  • Monkay: lifecycle coordinator for imports, settings, instances, and extensions
  • load, load_any, absolutify_import: import/path helpers
  • Cage, TransparentCage: context-isolated mutable proxies
  • Lifespan, LifespanHook: ASGI lifespan utilities
  • find_missing, sorted_exports: export inspection and debugging helpers

Public API Stability

Monkay keeps top-level public imports stable via monkay.__all__:

  • Monkay
  • DeprecatedImport
  • PRE_ADD_LAZY_IMPORT_HOOK
  • ExtensionProtocol
  • load, load_any, absolutify_import
  • InGlobalsDict, UnsetError, get_value_from_settings
  • Cage, TransparentCage

Documentation

Full docs: monkay.dymmond.com

Recommended order:

  1. Getting Started
  2. Tutorials
  3. Concepts
  4. How-to Guides
  5. Reference

Development Quickstart

Monkay uses hatch, ruff, ty, pytest, and mkdocs/zensical.

pip install hatch
hatch run lint
hatch run check_types
hatch test
hatch run docs:build

If you use Task, Monkay ships both Taskfile.yml and Taskfile.yaml:

task check
task coverage
task docs
task docs:serve

Contributing

See Contributing for setup, quality gates, docs workflow, and pull request expectations.

Metadata

Release files for monkay 0.5.3

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

Source distribution (sdist)

Source distribution for monkay 0.5.3
File Size Uploaded
monkay-0.5.3.tar.gz 71.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for monkay 0.5.3
File Interpreter ABI Platform
monkay-0.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 104.6 kB

Release files / monkay-0.5.3.tar.gz

Download URL monkay-0.5.3.tar.gz
Size 71.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4601797cfae1c80deafeeca7de24796c8bf53b7bb0d182af2c6acbefaf27bcac
BLAKE2b-256 checksum
How to use checksums
038d2a2bd4278801e99b601d24f67706c083ea2c79938cab0d67ee7a9d13048a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.10.20 HTTPX/0.28.1

Release files / monkay-0.5.3-py3-none-any.whl

Download URL monkay-0.5.3-py3-none-any.whl
Size 33.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
effe438b07fad650ef2d534f07f3d00fb5b8a61917767cfa26156b80e1b51240
BLAKE2b-256 checksum
How to use checksums
114b2130545528bd2ba250e9e63456c315e1812498830bd7b2e52c08c619380c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.10.20 HTTPX/0.28.1

Release history Release notifications | RSS feed

This release

0.5.3 This release

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

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