Skip to main content

FastDI — Rust-powered Dependency Injection for Python

Project description

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastdi_core-0.1.0.tar.gz (90.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastdi_core-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (351.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

fastdi_core-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (297.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.0-cp312-cp312-macosx_10_13_universal2.whl (509.3 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

fastdi_core-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (353.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

fastdi_core-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.0-cp311-cp311-macosx_10_13_universal2.whl (512.7 kB view details)

Uploaded CPython 3.11macOS 10.13+ universal2 (ARM64, x86-64)

fastdi_core-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl (353.8 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

fastdi_core-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.0-cp310-cp310-macosx_10_13_universal2.whl (512.8 kB view details)

Uploaded CPython 3.10macOS 10.13+ universal2 (ARM64, x86-64)

fastdi_core-0.1.0-cp39-cp39-musllinux_1_2_x86_64.whl (353.8 kB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

fastdi_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.0-cp39-cp39-macosx_10_13_universal2.whl (512.9 kB view details)

Uploaded CPython 3.9macOS 10.13+ universal2 (ARM64, x86-64)

fastdi_core-0.1.0-cp38-cp38-musllinux_1_2_x86_64.whl (352.9 kB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

fastdi_core-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (299.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.0-cp38-cp38-macosx_10_13_universal2.whl (510.9 kB view details)

Uploaded CPython 3.8macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file fastdi_core-0.1.0.tar.gz.

File metadata

  • Download URL: fastdi_core-0.1.0.tar.gz
  • Upload date:
  • Size: 90.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastdi_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8cbea0114471da534184567e94cf4c931756baf02e6b305ecdb1978290a9ec61
MD5 aa845d85ad08f413ee455bf0c4a4a73d
BLAKE2b-256 22c8ee58af367983eb56d5760801760642bc8b4f59fd06504bd977f4c42256fc

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2ea857bf7ce10bf55ff1a0032426962a69a51cc5edbdc969427586c8c5daad0b
MD5 08c8bae900d3a6da711d1e7c02c39db3
BLAKE2b-256 750ba9a7074d3209a4a68c58c8494e447ed0cd983192170b5c98211c7a88274b

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1aef04d3f33c20e0978adfe13d85a86124b32da1248d5cea7d7379683b5593cc
MD5 79c8b81debbe3e5f9336e1ab3314558b
BLAKE2b-256 b2a349f15c0af6a504f38ede3cf726490e65325397ce4b5eab587919adcca2aa

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 2719b245b18436d28c1528f5d776cee04798af1d83ee24bd5d3212c6e7fa3a80
MD5 59cbddfc9ca5529de6a0fb08642e170e
BLAKE2b-256 eb964509c480554bfe8957925e347ed892c85b1f9a40d2e98edbf1a515cc1121

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ec716bceab28703163afe86e9bd2bcdf82e041062c172df9c536584f165c65ec
MD5 51092ce9c02000a85b3dd1a5f1693d44
BLAKE2b-256 9fcf846c4dc5e21a49e70ab60c1cd94a69d67214c2fa5afb85d04795b97aa102

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d6d92c5a95fc26cf0e1f42adcf1e25f60c47cf07f7e82d8d189317f90bfd573c
MD5 15fca6be0be3f98d1081f845a362abe5
BLAKE2b-256 a6976874b571fbd82dbfea644aeb9d2ce55d676422606a45d04c066e2465c8b0

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp311-cp311-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp311-cp311-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 84624f78be3790d6968181d588e28c614833846d161e044ac30a64d7427eec93
MD5 8a28bdefd43d13ecd547e853a4a9fc03
BLAKE2b-256 ab9a46dcfffd93230dd7804048011d746232fb1c4ce1121760542afd3ca4aebe

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ecb436a009afa997db6fc17d13adf6f95d5d39fea3119754965649bd4c36915
MD5 d8683874305ee009d837d4ed20406962
BLAKE2b-256 2ceafdc05c49da459a5b3aa3e6698566a437e2e2985039ed8360b0bf23e95493

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97101b2b368acf7d327e5b97b1cb887f44c48513bbb7781e428d599d7226c9a9
MD5 f9e7d71f95ec74c99d270f2a2f30d1fd
BLAKE2b-256 dd474dccf6ab5d87c1869eabbfa490e6a4922358f4af734b7ea93dbdcfd59ae3

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp310-cp310-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp310-cp310-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 1e4f802311a2c145035975b77089831d818e9797ed65ee7d8f9815f2f4e2b910
MD5 95f2f4643e8138cc1f76462c452c6149
BLAKE2b-256 0b582db29dd2730d206fa5cae9c01e664022456fd46e46c548e25a3bc37d14d6

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a0f6a44a31b096e66380f8574c2529c4d98ab24e6a6f0a4d8b1b48f81d3768f2
MD5 ce50e0a9cd1f1c9a46e705b18de8fb80
BLAKE2b-256 2ab4e47a7c979315768d7e5f54be9e37dc8741fb899b5e452ef4e7eeb0141af1

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b723cb299ea9cb9d478175a9f57fb15806d5cf491b7362ab971e0574a7ca10b9
MD5 7206135af7789ef3250e8871bc389b12
BLAKE2b-256 f688cec477a314006aaece72f09ffd1db142dd166f03c6f433735c528d3b50bd

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp39-cp39-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp39-cp39-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 b6a64d5745eb0e7cb14376656666e60d578c23b8cbbcbf6f3276a894c8978623
MD5 3c4806d783a73c3ec26a5aa32f76012f
BLAKE2b-256 1ecde0cbfce710bd889ae5e0d6330850042d9078a07f570b1816e64bbc5df35a

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ea25c13001875338dfdb1efc33c9d61ceafd2781646b0378311a5cb41bccd32e
MD5 0e738e7adc2dd3441ec76d52586f3224
BLAKE2b-256 7d62bee983f399db2fab19e6df5d642808a13753ad3d897317206d37b5ed49e4

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16ce852b2c95a1d08ecf04f25ad026957f13a88e1e5580cda1b87a249f300632
MD5 731f81aa99f3ee37cbbc0c6a0ed76be4
BLAKE2b-256 94996f3b508f00865f5dda4813f858eac863fbf0fb63b9dc75cd5ec7c40d4ce3

See more details on using hashes here.

File details

Details for the file fastdi_core-0.1.0-cp38-cp38-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for fastdi_core-0.1.0-cp38-cp38-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 66bfbcf8841c9ad67c8ddb54a41717f90a0383749c0e89a6f4e4a99015a318d0
MD5 d7d78464cb7a7b75e63774d0198b80b5
BLAKE2b-256 14d2fdc07d9b5627c3cbad41221da959c21f7b990789bb6b149e77ed43db2cff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page