FastDI — Rust-powered Dependency Injection for Python
FastDI wraps a Rust core (PyO3) in a friendly Python API so you can wire services quickly without sacrificing performance. It supports sync and async providers, request-scoped caches, layered overrides, and observability hooks.
Project homepage: https://aliev.me/fastdi
Highlights
- Rust-backed plan compilation with cycle detection
- Sync (
@inject) and async (@ainject) decorators with minimal boilerplate - Caching scopes: transient, singleton, and per-request (async task)
- Overrides for tests and temporary wiring changes
- Hooks that report provider timings and cache hits
Requirements
- Python 3.9+
- Rust toolchain (stable)
Quick Start
pip install fastdi-core
# or set up a dev env with uv
uv venv .venv
. .venv/bin/activate
uv sync --dev
uv run maturin develop -r -q
uv run python -m examples.basic
Minimal Usage
from typing import Annotated, Protocol
from fastdi import Container, Depends, provide, inject
container = Container()
class Service(Protocol):
def ping(self) -> dict: ...
@provide(container, singleton=True)
def get_db() -> dict:
return {"db": "connection"}
@provide(container)
def get_service(db: Annotated[dict, Depends(get_db)]) -> Service:
class ServiceImpl:
def __init__(self, db):
self._db = db
def ping(self) -> dict:
return {"ok": True, "via": self._db["db"]}
return ServiceImpl(db)
@inject(container)
def handler(service: Annotated[Service, Depends(get_service)]):
return service.ping()
print(handler())
Async + Request Scope
import asyncio
from typing import Annotated
from fastdi import Container, Depends, provide, ainject
container = Container()
@provide(container, scope="request")
async def request_id() -> object:
return object()
@ainject(container)
async def within_task(
first: Annotated[object, Depends(request_id)],
second: Annotated[object, Depends(request_id)],
) -> bool:
return first is second
print(asyncio.run(within_task())) # True: value is cached within a task
Observability Hooks
from fastdi import Container
container = Container()
container.add_hook(lambda event, payload: print(event, payload))
Development Tasks
uv run python -m pytest -q # tests
uv run ruff check . # lint
uv run mypy . # type check
uv run python -m mkdocs serve # docs preview
Documentation
Full guides live under docs/ and the published site (see mkdocs.yml). Key entries:
- Getting started walkthrough
- Usage guide covering providers, scopes, and overrides
- Observability hooks and performance notes
License
MIT
Metadata
Release files for fastdi-core 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastdi_core-0.1.4.tar.gz | 72.2 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastdi_core-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ x86-64 | Details |
| fastdi_core-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| fastdi_core-0.1.4-cp39-abi3-macosx_10_13_universal2.whl | CPython 3.9 | abi3 | macOS 10.13+ universal2 (ARM64, x86-64) | Details |
Total release size: 1.3 MB
Release files / fastdi_core-0.1.4.tar.gz
| Download URL | fastdi_core-0.1.4.tar.gz |
|---|---|
| Size | 72.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa29864bf410f77a0ead6f707464183c42b31fac209d268beca733bc46bba8b3
|
|
BLAKE2b-256 checksum How to use checksums |
09c0fff4bdcab272a6a4945335f310fd94f096b4ba431a3e0a52b967455f9047
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / fastdi_core-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | fastdi_core-0.1.4-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 362.9 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d7d3730172239df64c60582d9056cef47dbc39a8c5ccfba14c9843ae79590dea
|
|
BLAKE2b-256 checksum How to use checksums |
43950728303a442aee8380e0d0bc937c826832ec21eabca63419112744b101bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / fastdi_core-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | fastdi_core-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 308.0 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fdadc2b16201b0ec0069c2341fb118e71ebf722b91974cd21ae2983656d3be96
|
|
BLAKE2b-256 checksum How to use checksums |
06f2b055e8b09c035dc14bd01b558d91a8de5b6b8aba3fee665c1e6e311fe1d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / fastdi_core-0.1.4-cp39-abi3-macosx_10_13_universal2.whl
| Download URL | fastdi_core-0.1.4-cp39-abi3-macosx_10_13_universal2.whl |
|---|---|
| Size | 534.5 kB |
| Tags | CPython 3.9 abi3 macOS 10.13+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
388f129110e9394369c24555f6471daec0e3fc484683db815acf67c872dc418b
|
|
BLAKE2b-256 checksum How to use checksums |
d6aafc092bea0be8dea00974f28ca1b4db2caa1bec110e4fba7c0221ba4d64be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|