fastapi-standalone-di
Use FastAPI's dependency injection outside of any web/ASGI context.
FastAPI ships a powerful dependency injection system — Depends, sub-dependencies,
yield teardown, per-resolution caching — but it is tightly coupled to the
request/response cycle. fastapi-standalone-di reuses that exact machinery so you
can resolve and invoke your dependencies from plain Python: CLI scripts, workers,
cron jobs, tests — no HTTP server required.
Install
pip install fastapi-standalone-di
# or
uv add fastapi-standalone-di
Usage
Resolve any callable that uses Depends(), exactly as FastAPI would:
import asyncio
from fastapi import Depends
from fastapi_standalone_di import FastAPIContainer
def get_settings() -> dict[str, str]:
return {"db_url": "postgres://localhost/app"}
class Database:
def __init__(self, settings: dict[str, str] = Depends(get_settings)) -> None:
self.url = settings["db_url"]
async def main() -> None:
async with FastAPIContainer() as container:
db = await container.get(Database)
print(db.url) # postgres://localhost/app
asyncio.run(main())
Sub-dependencies, yield teardown, caching, scopes, dependency overrides,
registrable interfaces, per-package binding discovery, shared app state,
application-lifetime singletons, loop-safe execution without a threadpool hop,
standalone Request/Response stubs, and query/path/header/cookie parameters are
all covered in the documentation.
Documentation
Full documentation is available at toilal.github.io/fastapi-standalone-di.
The in-development docs (built from develop) are previewed at
toilal.github.io/fastapi-standalone-di/dev/.
Requirements
- Python ≥ 3.11
- FastAPI ≥ 0.61
License
MIT © Rémi Alvergnat
CHANGELOG
v0.13.0 (2026-10-25)
Bug Fixes
Features
v0.12.1 (2026-10-20)
Performance Improvements
- Mark the built-in dependencies as loop-safe
(
16a1f09)
v0.12.0 (2026-10-16)
Bug Fixes
- Await functools.wraps-wrapped coroutine dependencies like FastAPI
(
682ef1d)
Features
- Call loop-safe sync dependencies without a threadpool hop
(
81d7e23)
v0.11.1 (2026-07-09)
Bug Fixes
-
Resolve only the return annotation in _return_class (#59,
50847c9) -
Resolve only the return annotation in _return_class (#58) (#59,
50847c9)
v0.11.0 (2026-07-09)
Features
- @provides ranking (primary + marked>unmarked) and generator unwrapping in auto_bindings
(#56,
7af3ea9)
v0.10.0 (2026-07-09)
Features
v0.9.0 (2026-07-09)
Features
v0.8.0 (2026-07-09)
Features
v0.7.0 (2026-07-09)
Bug Fixes
Features
v0.6.0 (2026-07-08)
Features
-
Auto_bindings() to wire interfaces to implementations by convention (#46,
c7705de) -
Auto_bindings() — wire interfaces to implementations by convention (#46,
c7705de)
v0.5.1 (2026-07-08)
Bug Fixes
-
Bind the passed package's own module in register_bindings (#44,
8ee830f) -
Wire a package's own binding module in register_bindings (#44,
8ee830f)
v0.5.0 (2026-07-08)
Features
v0.4.1 (2026-07-08)
Bug Fixes
v0.4.0 (2026-07-08)
Features
v0.3.0 (2026-07-07)
Features
v0.2.0 (2026-07-05)
Features
Changelog entries are generated automatically by python-semantic-release from Conventional Commits on release.
Metadata
Release files for fastapi-standalone-di 0.13.0
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 |
|---|---|---|---|---|
| fastapi_standalone_di-0.13.0.tar.gz | 187.9 kB | Without provenance | Details for fastapi_standalone_di-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_standalone_di-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_standalone_di-0.13.0-py3-none-any.whl |
Total release size: 231.1 kB
Release files / fastapi_standalone_di-0.13.0.tar.gz
| Download URL | fastapi_standalone_di-0.13.0.tar.gz |
|---|---|
| Size | 187.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b48ffcffc0dd8ad26478883ade0128cde4ba08df02c8484693a6916f3021f6ac
|
|
BLAKE2b-256 checksum How to use checksums |
37f0d3610d9d825dfed7e2a56d73544e8404adc06078d3c874a12ca46897cc9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fastapi_standalone_di-0.13.0-py3-none-any.whl
| Download URL | fastapi_standalone_di-0.13.0-py3-none-any.whl |
|---|---|
| Size | 43.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c55f785ce3560c635f32b1bdb72b6eaa89d0ae40729ad238277ec7f1980daa9d
|
|
BLAKE2b-256 checksum How to use checksums |
e4c91fd230e0ebb679576b46138d243d4bff84886cebe52ea6f5ae25942b7e64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for fastapi-standalone-di 0.13.0
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.