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.1.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.1-cp312-cp312-musllinux_1_2_x86_64.whl (358.2 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

fastdi_core-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (304.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.1-cp312-cp312-macosx_10_13_universal2.whl (516.5 kB view details)

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

fastdi_core-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (360.7 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

fastdi_core-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.1-cp311-cp311-macosx_10_13_universal2.whl (519.8 kB view details)

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

fastdi_core-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl (360.8 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

fastdi_core-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.1-cp310-cp310-macosx_10_13_universal2.whl (519.8 kB view details)

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

fastdi_core-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl (360.8 kB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

fastdi_core-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.1-cp39-cp39-macosx_10_13_universal2.whl (520.0 kB view details)

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

fastdi_core-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl (359.7 kB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

fastdi_core-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (306.0 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

fastdi_core-0.1.1-cp38-cp38-macosx_10_13_universal2.whl (518.1 kB view details)

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

File details

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

File metadata

  • Download URL: fastdi_core-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 dae02230bf3a7a9fc1b683e84792429b5b67183bd0a2ce12ffd66b000804ec44
MD5 087109d9857697a75988ba183fe92928
BLAKE2b-256 c715b4355f798e624b667b8917a4fa9ca5d3847ffb278fa324ef6c5bb46b0a94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 05f5ac5832fdd94a51f67929ebc4f71c06a9ab2c217f3d3769163e9367ce75b9
MD5 3b1d9c3b109bcd14cd80741441d97f0e
BLAKE2b-256 7ec9c39af14cbf9e81dd9937a9a03ad18f1c155f09850352b5d61e3cb39595ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2906c52dcd3b3bea62f3c5aa6b2006f94f5b0bd2bbee701d171f2b243f0fbe8
MD5 d816cf06f503878ad4cedadb618e9895
BLAKE2b-256 c78c2eabb53c817d21cc0be5f19a77bf9d0274c675e8bff3c8843d2d4e5d87e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 737b05664779d1263fc4600196057081cd8fd276f94356238b31421078d4fc30
MD5 89017a46f7d24963d14a1ee1baae043b
BLAKE2b-256 8210ab846a126f31c656733c0f7b5c094a765ec699a2b4d670e0cccd3d8aa9c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 43a3ee84f020691241483bbf12694af7f6b0c6b07049b929afd22b560d4c321f
MD5 37f7716c66de414d9eecfc86a8507a34
BLAKE2b-256 61c3584e7c0a1e563992c9e57676c023438d66699e989ec0aff4c13f0e7ceabd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2c6a8990acaa23bda3d5a8ca88c18a36adffdf8a8ce0a408048dbccd31d7e67
MD5 364e4ea17efa746c2cc4a884b7378f62
BLAKE2b-256 f66861f7eef07ae2d8c01cd1f2063b3f6da108d48e1964a45de6dcd215805940

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp311-cp311-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 936c93775410b7952653933f5528f28725ff5aae209d8cbc7d2b038c1661a0a3
MD5 26fc81f5d16f282b31c8b972aed52ccd
BLAKE2b-256 e92117f85c620e606e424b5aa9c98b32130fe5fc09872c59a3862b5d2600517c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8e9a94a29621d1640f4276d858a9d67ccd54cee767c5e6d615e9b4b3daf6a24e
MD5 6c7532fdbf2a2f8b2dc097e2b4cf0695
BLAKE2b-256 edacd135ac928abefd9931399456024aa68fb2e93f945468a150adec8cea3eb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43d64e8a42a12aa77192333a75c5409ecd0aced2e291dcd133fcb142e02d1766
MD5 dcf84bae51d4077cf145941ebdb29f22
BLAKE2b-256 ff20fd71946325005ab3064353566862a00119e8dda264b4edc02eda82016d98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp310-cp310-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 09a28d8f1b9e55c44200ffb5aa3c842f682b8a0b13b63c100a155a010c2abb15
MD5 b1318f6e66dca76f2407e3462cce4879
BLAKE2b-256 cea2df19eab5dab5f382f0eb32bcdd619a6cf3d96487d37343f1355abd28d740

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1df2d3ed5989eed59912aae441aa1e60e77883a9f6342688fc369ab2e26a1ec0
MD5 8079ea5eba4f80ff2ff967fa2071bc92
BLAKE2b-256 5ca76241a1c6a89bc525a661722ba19a9a16c5241288d311bad2abb1c903ce8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 912453b2a707808b3e808ff3479e9cc664c823c834c2dc3c7542d3fcbdfdc376
MD5 2875cc2472fe4225b6f3d86c6476b977
BLAKE2b-256 07c14aff550d3c3253d26ef8eaf6564d5de7bc9643226c964dda81feebf27b3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp39-cp39-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 2a1a1251f2aed204f0b069421ab2b39b3763efe6516a0af2853d2107766d91db
MD5 1ce3efb17e21e29b03c0c77ad20b7f8e
BLAKE2b-256 074c8e1f6d5dedbe98a2cdf85269cb858fd2d97231870f7a4221455c3aeaf02f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 da824fac7711bbc2d5da9a2655b8cc3ae9bed59a0577e674c95291b197a37f86
MD5 fabfc1b88765c747bc5bbccd00aaf580
BLAKE2b-256 7e19f41fa548f40a45a02df1783d25bd596858447eab54209f1ca629da1f8cbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adcbc7a7ffecda4fd0dd607fde5b79ae643af0cf5f3d3f79dcd5beed21abf819
MD5 0b6efe991606c1af9c8ef65d57962188
BLAKE2b-256 e70a53dace3992cfb7b6b79312d98038b36d89cc6324b240fd4bb525feeef2ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastdi_core-0.1.1-cp38-cp38-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3942a4cc2ad7f08ba674c2794dd745d4d04a891b4ef7e3b1158d157fd5c70527
MD5 8de2460d49fabbcf29a7665116953ed1
BLAKE2b-256 8b4df0705d9f73d145ca5d57ea90697fa7a00587fb3e69087de157c9fc5aada5

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