Skip to main content

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 AsyncExitStack and ContextVar
  • 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

uncalled_for-0.4.0.tar.gz (57.0 kB view details)

Uploaded Source

Built Distribution

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

uncalled_for-0.4.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

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

Hashes for uncalled_for-0.4.0.tar.gz
Algorithm Hash digest
SHA256 335b95bd2422332ec210d518f314a16e4c640921c39fc8bf2ad095bd3538f4af
MD5 028b8f96fee7968e75f85c41ff103cbf
BLAKE2b-256 6b5a92ce0b3ea5481915f55da994c2c2c5f7a3c09949afde196ee89f8ab961aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for uncalled_for-0.4.0.tar.gz:

Publisher: publish.yml on chrisguidry/uncalled-for

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

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

Hashes for uncalled_for-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16c4bb3337532e4bd5569adc192285976f3ad5305402256d34c67a12b5c968bd
MD5 050dd24ee36bb3e3c8c26b1fd37f46df
BLAKE2b-256 a24097cec87c077eb3291fc7905e6633e08b7ca593c57d30238444bcb6bb3d53

See more details on using hashes here.

Provenance

The following attestation bundles were made for uncalled_for-0.4.0-py3-none-any.whl:

Publisher: publish.yml on chrisguidry/uncalled-for

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

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page