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.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.11.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_standalone_di-0.11.1.tar.gz | 175.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_standalone_di-0.11.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 214.2 kB
Release files / fastapi_standalone_di-0.11.1.tar.gz
| Download URL | fastapi_standalone_di-0.11.1.tar.gz |
|---|---|
| Size | 175.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ec5eb7004c33076f16e243f6c95c073654b00603657e2f4f5fee25bc7806322
|
|
BLAKE2b-256 checksum How to use checksums |
d55370868eb8c85f2dfd4f7f4fbf4ff873590acc9b947644ec4878583da3623c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / fastapi_standalone_di-0.11.1-py3-none-any.whl
| Download URL | fastapi_standalone_di-0.11.1-py3-none-any.whl |
|---|---|
| Size | 38.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15ec23ae764666b9b95ca80d9c4f88efe544c1ca1543157de6784fe9728670ff
|
|
BLAKE2b-256 checksum How to use checksums |
5153dfd6cc21bf1bb7499e6f1bd418966beaa191d1f1bc50cbd27fb5945c9127
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|