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, 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.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.
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 fastapi_standalone_di-0.7.0.tar.gz.
File metadata
- Download URL: fastapi_standalone_di-0.7.0.tar.gz
- Upload date:
- Size: 160.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4026512c71d3724cd4ffe58a366bb042321c53bccc8eedb88c71e15de510e425
|
|
| MD5 |
0cdbe3f56f475f063f24a64548a3fa77
|
|
| BLAKE2b-256 |
a5f2d38f18e2de561f46d8e4efd40d697fd67b89248482fbc8ba361d97664f84
|
File details
Details for the file fastapi_standalone_di-0.7.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_standalone_di-0.7.0-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3187de8fdd836e3d2bcf653e3f0fe4a05ef3d43a2cf1a514bcfe247033ebf9cf
|
|
| MD5 |
110c82cc30cc953cadb86fd773dcd509
|
|
| BLAKE2b-256 |
ab1473f1f9b60c6ebe99be1f453210bf0904ea4e5246e75f1373516449c17dd4
|