Skip to main content

Runtime capability registry for optional Python dependencies

Project description

Pantry

Runtime capability registry for optional Python dependencies.

Pantry discovers optional dependency groups declared in pyproject.toml, probes which packages are actually installed, and exposes a clean API to check availability and guard functions via decorators.

Installation

pip install mypantry

Quick start

import pantry

# Subscript access — raises if missing
PIL = pantry["pillow"]
img = PIL.Image.open("photo.jpg")

# Safe access — returns None (or a default) if missing
np = pantry.get("numpy")
redis = pantry.get("redis", None)

# Check availability
if pantry.has("pillow"):
    ...

# Check multiple packages at once
if pantry.has("numpy", "pandas"):
    ...

# Guard a function via decorator
@pantry("numpy", "pandas")
def analyze(data):
    import numpy as np
    import pandas as pd
    ...

# Print a summary
print(pantry.report())

Explicit construction

When you need a Pantry instance from a specific pyproject.toml:

from pantry import Pantry

p = Pantry.from_pyproject("path/to/pyproject.toml")
p = Pantry.discover()  # walks upward from cwd

API

Module-level usage

import pantry returns a Pantry instance that auto-discovers your pyproject.toml.

pantry[pkg]

Return the imported module. Raises RuntimeError if the package is not available.

pantry.get(pkg, default=None) -> module | None

Return the imported module, or default if the package is not available.

pantry.has(*pkgs) -> bool

True if all listed packages are installed and importable.

pantry.has_group(group) -> bool

True if at least one package in the named group is available.

pantry(*pkgs)

Decorator. Raises RuntimeError at call time if any listed package is missing.

pantry.report() -> str

Formatted table of all probed packages with availability status.

Pantry.discover(start=None)

Find pyproject.toml by walking upward from start (default: cwd), then probe all optional dependencies.

Pantry.from_pyproject(path)

Parse a specific pyproject.toml and probe.

Requirements

  • Python 3.11+
  • packaging (only runtime dependency)

License

Apache License 2.0

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

mypantry-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

mypantry-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file mypantry-0.1.0.tar.gz.

File metadata

  • Download URL: mypantry-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mypantry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efae5d3d7e561d934176e8add421ce5118cfe52cb7641564f903faa760b6cf6f
MD5 29a877f2952b543cb1f556c0d87a2f29
BLAKE2b-256 342ca0e995503fa73c637b978f15f2fba74f838b29aaa5bc14315f9590ecf062

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypantry-0.1.0.tar.gz:

Publisher: publish.yml on genropy/genro-pantry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mypantry-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mypantry-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mypantry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa9ad6e79a0d7187f9a69b65f4a3269e9feb58d7bf5e1203afe00d16ee029ef7
MD5 d4eb306084f1150398c1cbcb0665082c
BLAKE2b-256 89d07914fbf9c18590c959bdd872054b1dfb0de4d4ea9d3c99611defdcdc9511

See more details on using hashes here.

Provenance

The following attestation bundles were made for mypantry-0.1.0-py3-none-any.whl:

Publisher: publish.yml on genropy/genro-pantry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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