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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efae5d3d7e561d934176e8add421ce5118cfe52cb7641564f903faa760b6cf6f
|
|
| MD5 |
29a877f2952b543cb1f556c0d87a2f29
|
|
| BLAKE2b-256 |
342ca0e995503fa73c637b978f15f2fba74f838b29aaa5bc14315f9590ecf062
|
Provenance
The following attestation bundles were made for mypantry-0.1.0.tar.gz:
Publisher:
publish.yml on genropy/genro-pantry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypantry-0.1.0.tar.gz -
Subject digest:
efae5d3d7e561d934176e8add421ce5118cfe52cb7641564f903faa760b6cf6f - Sigstore transparency entry: 1191198877
- Sigstore integration time:
-
Permalink:
genropy/genro-pantry@0c69be8c8c5eef37adacfaaee207ee75f375384e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0c69be8c8c5eef37adacfaaee207ee75f375384e -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa9ad6e79a0d7187f9a69b65f4a3269e9feb58d7bf5e1203afe00d16ee029ef7
|
|
| MD5 |
d4eb306084f1150398c1cbcb0665082c
|
|
| BLAKE2b-256 |
89d07914fbf9c18590c959bdd872054b1dfb0de4d4ea9d3c99611defdcdc9511
|
Provenance
The following attestation bundles were made for mypantry-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on genropy/genro-pantry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mypantry-0.1.0-py3-none-any.whl -
Subject digest:
fa9ad6e79a0d7187f9a69b65f4a3269e9feb58d7bf5e1203afe00d16ee029ef7 - Sigstore transparency entry: 1191198880
- Sigstore integration time:
-
Permalink:
genropy/genro-pantry@0c69be8c8c5eef37adacfaaee207ee75f375384e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/genropy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0c69be8c8c5eef37adacfaaee207ee75f375384e -
Trigger Event:
push
-
Statement type: