PyBooster 💉
PyBooster - dependency injection without the boilerplate.
Documentation
Learn more here: https://ryanmorshead.com/pybooster
Install
pip install -U pybooster
At a Glance
Getting started with PyBooster involves a few steps:
- Define a provider function for a dependency.
- Add an injector to a function that will use that dependency.
- Activate a solution and call the dependent function in its context.
The example below injects a sqlite3.Connection into a function that executes SQL:
import sqlite3
from collections.abc import Iterator
from tempfile import NamedTemporaryFile
from pybooster import injector
from pybooster import provider
from pybooster import required
from pybooster import solution
@provider.contextmanager
def sqlite_connection(database: str) -> Iterator[sqlite3.Connection]:
with sqlite3.connect(database) as conn:
yield conn
@injector.function
def sql(cmd: str, *, conn: sqlite3.Connection = required) -> sqlite3.Cursor:
return conn.execute(cmd)
tempfile = NamedTemporaryFile()
with solution(sqlite_connection(tempfile.name)):
sql("CREATE TABLE example (id INTEGER PRIMARY KEY, name TEXT)")
sql("INSERT INTO example (name) VALUES ('alice')")
cursor = sql("SELECT * FROM example")
assert cursor.fetchone() == (1, "alice")
This works by inspecting the type hints of the provider sqlite_connection to see that
it produces a sqlite3.Connection. Simarly, the signature of the dependant function
query_database is inspected to see that it requires a sqlite3.Connection. At that
point, when query_database is called it checks to see if there's a
sqlite3.Connection provider in the current solution and, if so, injects it into the
function.
Metadata
Release files for pybooster 0.0.10
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 | Actions |
|---|---|---|---|---|
| pybooster-0.0.10.tar.gz | 36.1 kB | Without provenance | Details for pybooster-0.0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybooster-0.0.10-py3-none-any.whl | Python 3 | none | any | Details for pybooster-0.0.10-py3-none-any.whl |
Total release size: 57.8 kB
Release files / pybooster-0.0.10.tar.gz
| Download URL | pybooster-0.0.10.tar.gz |
|---|---|
| Size | 36.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4213d00519f358b677f1677d3789a6f73c5eb1760f78e395ea7b74b910b7a56a
|
|
BLAKE2b-256 checksum How to use checksums |
010bb325d019ddb2f78db2d0e9c3aab173b7ba71f0d65174fadb8ebd5939decd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Release files / pybooster-0.0.10-py3-none-any.whl
| Download URL | pybooster-0.0.10-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d26927e37de312382cfe50cca6025a4555ef6401857f5bdffd9b4952c17c47c4
|
|
BLAKE2b-256 checksum How to use checksums |
3df4bd1d350ff123d44770f912ae4a9846a07016ad18e73a06258047274a24c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.22
|
Security for pybooster 0.0.10
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.