Metadata-Version: 2.4
Name: fastapi-standalone-di
Version: 0.6.0
Summary: Use FastAPI's dependency injection outside of any web/ASGI context
Project-URL: Homepage, https://github.com/Toilal/fastapi-standalone-di
Project-URL: Repository, https://github.com/Toilal/fastapi-standalone-di
Project-URL: Changelog, https://github.com/Toilal/fastapi-standalone-di/blob/develop/CHANGELOG.md
Project-URL: Issues, https://github.com/Toilal/fastapi-standalone-di/issues
Author-email: Rémi Alvergnat <toilal.dev@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: asgi,container,dependency-injection,di,fastapi
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: fastapi<1.0,>=0.61
Description-Content-Type: text/markdown

# fastapi-standalone-di

[![Latest Version](https://img.shields.io/pypi/v/fastapi-standalone-di.svg)](https://pypi.python.org/pypi/fastapi-standalone-di)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Toilal/fastapi-standalone-di/blob/develop/LICENSE)
[![Build Status](https://img.shields.io/github/actions/workflow/status/Toilal/fastapi-standalone-di/ci.yml?branch=develop)](https://github.com/Toilal/fastapi-standalone-di/actions/workflows/ci.yml)
[![Codecov](https://img.shields.io/codecov/c/github/Toilal/fastapi-standalone-di)](https://codecov.io/gh/Toilal/fastapi-standalone-di)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/relekang/python-semantic-release)

Use [FastAPI](https://fastapi.tiangolo.com/)'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

```bash
pip install fastapi-standalone-di
# or
uv add fastapi-standalone-di
```

## Usage

Resolve any callable that uses `Depends()`, exactly as FastAPI would:

```python
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](https://toilal.github.io/fastapi-standalone-di/).
The in-development docs (built from `develop`) are previewed at
[toilal.github.io/fastapi-standalone-di/dev/](https://toilal.github.io/fastapi-standalone-di/dev/).

## Requirements

- Python ≥ 3.11
- FastAPI ≥ 0.61

## License

[MIT](./LICENSE) © Rémi Alvergnat


# CHANGELOG

<!-- version list -->

## v0.6.0 (2026-07-08)

### Features

- Auto_bindings() to wire interfaces to implementations by convention
  ([#46](https://github.com/Toilal/fastapi-standalone-di/pull/46),
  [`c7705de`](https://github.com/Toilal/fastapi-standalone-di/commit/c7705dead94c584cda71dc23b0a52146f3a2da47))

- Auto_bindings() — wire interfaces to implementations by convention
  ([#46](https://github.com/Toilal/fastapi-standalone-di/pull/46),
  [`c7705de`](https://github.com/Toilal/fastapi-standalone-di/commit/c7705dead94c584cda71dc23b0a52146f3a2da47))


## v0.5.1 (2026-07-08)

### Bug Fixes

- Bind the passed package's own module in register_bindings
  ([#44](https://github.com/Toilal/fastapi-standalone-di/pull/44),
  [`8ee830f`](https://github.com/Toilal/fastapi-standalone-di/commit/8ee830ff34fe8300286456cab086d8ebf94b5a24))

- Wire a package's own binding module in register_bindings
  ([#44](https://github.com/Toilal/fastapi-standalone-di/pull/44),
  [`8ee830f`](https://github.com/Toilal/fastapi-standalone-di/commit/8ee830ff34fe8300286456cab086d8ebf94b5a24))


## v0.5.0 (2026-07-08)

### Features

- Make lazy singletons usable as ASGI route dependencies
  ([#42](https://github.com/Toilal/fastapi-standalone-di/pull/42),
  [`bebe3e8`](https://github.com/Toilal/fastapi-standalone-di/commit/bebe3e8fdc94e1fde75fe073dcfc9179cee95566))


## v0.4.1 (2026-07-08)

### Bug Fixes

- Patch fastapi.params.Depends in place for registrable support (#40)
  ([#41](https://github.com/Toilal/fastapi-standalone-di/pull/41),
  [`08927a5`](https://github.com/Toilal/fastapi-standalone-di/commit/08927a574f58a6b2cee778abfc62f7e90011cb6f))


## v0.4.0 (2026-07-08)

### Features

- AppState-backed application singletons (ASGI + standalone)
  ([#39](https://github.com/Toilal/fastapi-standalone-di/pull/39),
  [`a87d11f`](https://github.com/Toilal/fastapi-standalone-di/commit/a87d11fbf51d2e2555173203a6a11f5dba209840))


## v0.3.0 (2026-07-07)

### Features

- Discover per-package di.py modules to auto-register bindings
  ([#37](https://github.com/Toilal/fastapi-standalone-di/pull/37),
  [`02fc05b`](https://github.com/Toilal/fastapi-standalone-di/commit/02fc05bd52b65a02b8cd3de5c740e80ef7000007))


## v0.2.0 (2026-07-05)

### Features

- Support Python 3.11 ([#35](https://github.com/Toilal/fastapi-standalone-di/pull/35),
  [`f399c8e`](https://github.com/Toilal/fastapi-standalone-di/commit/f399c8edf5f341d18e1af86761a79b86df260c4a))


Changelog entries are generated automatically by
[python-semantic-release](https://python-semantic-release.readthedocs.io/) from
[Conventional Commits](https://www.conventionalcommits.org/) on release.
