uncalled-for
Async dependency injection for Python functions.
Declare what your function needs as parameter defaults. They show up resolved when the function runs. No ceremony, no container, no configuration.
from uncalled_for import Depends
async def get_db():
db = await connect()
try:
yield db
finally:
await db.close()
async def handle_request(db: Connection = Depends(get_db)):
await db.execute("SELECT 1")
Features
- Zero dependencies — standard library only
- Async-native — built on
AsyncExitStackandContextVar - Context manager lifecycle — sync and async generators get proper cleanup
- Nested dependencies — dependencies can depend on other dependencies
- Caching — each dependency resolves once per call, even if referenced multiple times
- Call arguments — a factory can reference the arguments of the call it serves
Call arguments
A factory sometimes needs a value from the call itself, not from another
dependency. CallArgument declares that reference:
from uncalled_for import CallArgument, Depends
def load_user(user_id: str = CallArgument()) -> User:
return users[user_id]
async def handle_request(
user_id: str,
user: User = Depends(load_user),
):
...
The bare form takes the name of the parameter it is declared on.
CallArgument("name") names a different parameter of the outer function. The
reference sees the same value the outer function receives, whether the caller
passed it or another dependency on the outer signature produced it.
CallArgument(optional=True) yields None when the outer function has no
such argument. References that form a cycle raise CycleError.
Bindings
Depends accepts keyword bindings, so you can wire up an ordinary function
without changing it:
async def handle_request(
user_id: str,
user: User = Depends(load_user, user_id=CallArgument("user_id")),
):
...
A binding that is a Dependency, such as CallArgument(...) or another
Depends(...), resolves first and the factory receives its value. Any other
value passes through as it is. A binding replaces the factory parameter's own
default, which is then never resolved. Two dependencies on the same factory
share one cached result only when their bindings match.
Install
pip install uncalled-for
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 uncalled_for-0.4.0.tar.gz.
File metadata
- Download URL: uncalled_for-0.4.0.tar.gz
- Upload date:
- Size: 57.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
335b95bd2422332ec210d518f314a16e4c640921c39fc8bf2ad095bd3538f4af
|
|
| MD5 |
028b8f96fee7968e75f85c41ff103cbf
|
|
| BLAKE2b-256 |
6b5a92ce0b3ea5481915f55da994c2c2c5f7a3c09949afde196ee89f8ab961aa
|
Provenance
The following attestation bundles were made for uncalled_for-0.4.0.tar.gz:
Publisher:
publish.yml on chrisguidry/uncalled-for
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uncalled_for-0.4.0.tar.gz -
Subject digest:
335b95bd2422332ec210d518f314a16e4c640921c39fc8bf2ad095bd3538f4af - Sigstore transparency entry: 2409123915
- Sigstore integration time:
-
Permalink:
chrisguidry/uncalled-for@9228197fdb1ddbbc4a0b1ec4069efedaf15bc9bb -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/chrisguidry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9228197fdb1ddbbc4a0b1ec4069efedaf15bc9bb -
Trigger Event:
release
-
Statement type:
File details
Details for the file uncalled_for-0.4.0-py3-none-any.whl.
File metadata
- Download URL: uncalled_for-0.4.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16c4bb3337532e4bd5569adc192285976f3ad5305402256d34c67a12b5c968bd
|
|
| MD5 |
050dd24ee36bb3e3c8c26b1fd37f46df
|
|
| BLAKE2b-256 |
a24097cec87c077eb3291fc7905e6633e08b7ca593c57d30238444bcb6bb3d53
|
Provenance
The following attestation bundles were made for uncalled_for-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on chrisguidry/uncalled-for
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uncalled_for-0.4.0-py3-none-any.whl -
Subject digest:
16c4bb3337532e4bd5569adc192285976f3ad5305402256d34c67a12b5c968bd - Sigstore transparency entry: 2409124118
- Sigstore integration time:
-
Permalink:
chrisguidry/uncalled-for@9228197fdb1ddbbc4a0b1ec4069efedaf15bc9bb -
Branch / Tag:
refs/tags/0.4.0 - Owner: https://github.com/chrisguidry
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9228197fdb1ddbbc4a0b1ec4069efedaf15bc9bb -
Trigger Event:
release
-
Statement type: