🍞 puffpastry
A lightweight, intuitive, Pythonic dependency injection framework.
Highlights:
- 🍄 Micro framework with very little overhead - single file implementation and handful of public API methods, minimal third-party package requirements.
- 🌕 Unit-tests cover all core functionality, ruff and pre-commit used to ensure codebase health.
- 🐍 Compliant with latest Python 3.x version
Getting Started
To install from PyPI, use pip:
pip install puffpastry
The following example shows bootstrapping a webapp using fastapi with configuration read from environment (or from .env file, as we use python-dotenv under the hood). Of course, for such a minimal one-file implementation, dependency injection seems superfluous; but for larger codebases spread across multiple files this is a great way to manage dependencies and configuration.
from fastapi import FastAPI
from puffpastry import create, provides
from requests import get
class IpifyClient:
def __init__(self, base_url):
self.base_url = base_url
def ipv4(self):
return get(self.base_url).content.decode("utf8")
@provides("fastapi")
def fastapi_provider(app):
return FastAPI()
@provides("ipify_client")
def ipify_client(app):
# The base url will be read from IPIFY_BASE_URL env variable or .env file.
# To run this example set this value to 'https://api.ipify.org'
return IpifyClient(base_url=app.config.ipify_base_url)
@provides("home_route")
def home_route_provider(app):
@app.fastapi.get("/")
def home():
public_ip = app.ipify_client.ipv4()
return {"message": f"your public IP is {public_ip}"}
def create_app():
return create("my_app").load("fastapi", "ipify_client", "home_route")
app = create_app().fastapi
you can run this example with the fastapi CLI, assuming you saved the file as app.py:
fastapi dev app.py
See examples/ for more usage examples.
Metadata
Release files for puffpastry 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| puffpastry-0.0.3.tar.gz | 5.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| puffpastry-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.3 kB
Release files / puffpastry-0.0.3.tar.gz
| Download URL | puffpastry-0.0.3.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66ad0bf522d307bb58d6d16b294be45179fdf53aad5b8a7bc05d5af7d3c338f0
|
|
BLAKE2b-256 checksum How to use checksums |
412b0fb9e0a1272b8867c8f0d277e573dc0398391558430ea70c5bb0dc718167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / puffpastry-0.0.3-py3-none-any.whl
| Download URL | puffpastry-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9fc11d951be53c0cc4a88550085b35df25ae7c70228cb9d752b0443ceefa22ce
|
|
BLAKE2b-256 checksum How to use checksums |
07286672f8b1ba48bc83acfb0a0f25a295e33fc862a3f08c2cdcebf7b3389007
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for puffpastry 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.