Skip to main content

The ultimate preload, settings, lazy import manager.

Project description

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.

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

monkay-0.5.3.tar.gz (71.3 kB view details)

Uploaded Source

Built Distribution

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

monkay-0.5.3-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file monkay-0.5.3.tar.gz.

File metadata

  • Download URL: monkay-0.5.3.tar.gz
  • Upload date:
  • Size: 71.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.10.20 HTTPX/0.28.1

File hashes

Hashes for monkay-0.5.3.tar.gz
Algorithm Hash digest
SHA256 4601797cfae1c80deafeeca7de24796c8bf53b7bb0d182af2c6acbefaf27bcac
MD5 fd3e1f36b60a4219e78cb920b507e73f
BLAKE2b-256 038d2a2bd4278801e99b601d24f67706c083ea2c79938cab0d67ee7a9d13048a

See more details on using hashes here.

File details

Details for the file monkay-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: monkay-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.10.20 HTTPX/0.28.1

File hashes

Hashes for monkay-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 effe438b07fad650ef2d534f07f3d00fb5b8a61917767cfa26156b80e1b51240
MD5 2e5cd164cb332f29aa6477ea8136f76f
BLAKE2b-256 114b2130545528bd2ba250e9e63456c315e1812498830bd7b2e52c08c619380c

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