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.2.tar.gz (69.9 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.2-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for monkay-0.5.2.tar.gz
Algorithm Hash digest
SHA256 3c0064ee253b27329216314d1a6ab077e6e39ac2e7a3867feebaa026fce43829
MD5 f1d1fcb2b8a28a5ba75de45bb91cf917
BLAKE2b-256 b2076e358ce3cbfd925809131affa7090d4381f757fc3b171964c231e456c049

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for monkay-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6cb126a469b5397fce15dcc755edb9d6ade8287461f0782f57501e4266c21df
MD5 9aa520a95076a3d4651af3cb09d65537
BLAKE2b-256 1b6beb8d474a2e15362a135f7b876239a888a20a77c568903323e362ea7c01c3

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