fast-depends 3.0.8


pip install fast-depends

  Latest version

Released: Mar 02, 2026


Meta
Author: Nikita Pastukhov
Requires Python: >=3.10

Classifiers

Development Status
  • 5 - Production/Stable

License
  • OSI Approved :: MIT License

Programming Language
  • Python
  • Python :: Implementation :: CPython
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14

Operating System
  • OS Independent

Topic
  • Software Development :: Libraries :: Python Modules
  • Software Development :: Libraries
  • Software Development

Typing
  • Typed

Intended Audience
  • Developers
  • Information Technology

Framework
  • Pydantic
  • Pydantic :: 1
  • Pydantic :: 2

FastDepends

Tests coverage Coverage Package version downloads
Supported Python versions GitHub


Documentation: https://lancetnik.github.io/FastDepends/


FastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic. This is a small library which provides you with the ability to use lovely FastAPI interfaces in your own projects or tools.

Thanks to fastapi and pydantic projects for this great functionality. This package is just a small change of the original FastAPI sources to provide DI functionality in a pure-Python way.

Async and sync modes are both supported.

For why?

This project should be extremely helpful to boost your not-FastAPI applications (even Flask, I know that u like some legacy).

Also the project can be a core of your own framework for anything. Actually, it was build for my another project - :rocket:Propan:rocket: (and FastStream), check it to see full-featured FastDepends usage example.

Installation

pip install fast-depends

Usage

There is no way to make Dependency Injection easier

You can use this library without any frameworks in both sync and async code.

Async code

import asyncio

from fast_depends import inject, Depends

async def dependency(a: int) -> int:
    return a

@inject
async def main(
    a: int,
    b: int,
    c: int = Depends(dependency)
) -> float:
    return a + b + c

assert asyncio.run(main("1", 2)) == 4.0

Sync code

from fast_depends import inject, Depends

def dependency(a: int) -> int:
    return a

@inject
def main(
    a: int,
    b: int,
    c: int = Depends(dependency)
) -> float:
    return a + b + c

assert main("1", 2) == 4.0

@inject decorator plays multiple roles at the same time:

  • resolve Depends classes
  • cast types according to Python annotation
  • validate incoming parameters using pydantic

Features

Synchronous code is fully supported in this package: without any async_to_sync, run_sync, syncify or any other tricks.

Also, FastDepends casts functions' return values the same way, it can be very helpful in building your own tools.

These are two main defferences from native FastAPI DI System.


Dependencies Overriding

Also, FastDepends can be used as a lightweight DI container. Using it, you can easily override basic dependencies with application startup or in tests.

from typing import Annotated

from fast_depends import Depends, dependency_provider, inject

def abc_func() -> int:
    raise NotImplementedError()

def real_func() -> int:
    return 1

@inject
def func(
    dependency: Annotated[int, Depends(abc_func)]
) -> int:
    return dependency

with dependency_provider.scope(abc_func, real_func):
    assert func() == 1

dependency_provider in this case is just a default container already declared in the library. But you can use your own the same way:

from typing import Annotated

from fast_depends import Depends, Provider, inject

provider = Provider()

def abc_func() -> int:
    raise NotImplementedError()

def real_func() -> int:
    return 1

@inject(dependency_overrides_provider=provider)
def func(
    dependency: Annotated[int, Depends(abc_func)]
) -> int:
    return dependency

with provider.scope(abc_func, real_func):
    assert func() == 1

This way you can inherit the basic Provider class and define any extra logic you want!


Custom Fields

If you wish to write your own FastAPI or another closely by architecture tool, you should define your own custom fields to specify application behavior.

Custom fields can be used to adding something specific to a function arguments (like a BackgroundTask) or parsing incoming objects special way. You able decide by own, why and how you will use these tools.

FastDepends grants you this opportunity a very intuitive and comfortable way.

from fast_depends import inject
from fast_depends.library import CustomField

class Header(CustomField):
    def use(self, /, **kwargs: AnyDict) -> AnyDict:
        kwargs = super().use(**kwargs)
        kwargs[self.param_name] = kwargs["headers"][self.param_name]
        return kwargs

@inject
def my_func(header_field: int = Header()):
    return header_field

assert my_func(
    headers={ "header_field": "1" }
) == 1
3.0.8 Mar 02, 2026
3.0.7 Mar 02, 2026
3.0.6 Feb 26, 2026
3.0.5 Nov 30, 2025
3.0.4 Nov 30, 2025
3.0.3 Oct 19, 2025
3.0.2 Oct 14, 2025
3.0.1 Oct 12, 2025
3.0.0 Oct 11, 2025
3.0.0rc1 Aug 12, 2025
3.0.0rc0 Aug 12, 2025
3.0.0a12 Jul 28, 2025
3.0.0a11 Jul 20, 2025
3.0.0a10 Jul 11, 2025
3.0.0a9 Jun 26, 2025
3.0.0a8 Jun 25, 2025
3.0.0a7 Jun 24, 2025
3.0.0a6 Jun 24, 2025
3.0.0a5 Jun 15, 2025
3.0.0a4 Jun 15, 2025
3.0.0a3 Nov 05, 2024
3.0.0a2 Oct 31, 2024
3.0.0a1 Oct 29, 2024
3.0.0a0 Sep 05, 2024
2.4.12 Oct 16, 2024
2.4.11 Aug 27, 2024
2.4.10 Aug 24, 2024
2.4.9 Aug 22, 2024
2.4.8 Aug 11, 2024
2.4.7 Jul 24, 2024
2.4.6 Jul 12, 2024
2.4.5 Jul 11, 2024
2.4.4 Jun 06, 2024
2.4.3 May 25, 2024
2.4.2 Feb 27, 2024
2.4.1 Feb 25, 2024
2.4.0 Feb 20, 2024
2.4.0b0 Jan 15, 2024
2.3.1 Jan 10, 2024
2.3.0 Jan 09, 2024
2.2.8 Dec 22, 2023
2.2.7 Dec 22, 2023
2.2.6 Dec 15, 2023
2.2.5 Dec 14, 2023
2.2.4 Dec 13, 2023
2.2.3 Nov 14, 2023
2.2.2 Nov 08, 2023
2.2.1 Oct 03, 2023
2.2.0 Sep 22, 2023
2.1.9 Aug 21, 2023
2.1.8 Aug 19, 2023
2.1.7 Aug 17, 2023
2.1.6 Aug 09, 2023
2.1.5 Aug 05, 2023
2.1.4 Jul 23, 2023
2.1.3 Jul 20, 2023
2.1.2 Jul 18, 2023
2.1.1 Jul 17, 2023
2.1.0 Jul 17, 2023
2.0.5 Jun 25, 2023
2.0.4 Jun 23, 2023
2.0.3 Jun 23, 2023
2.0.2 Jun 22, 2023
2.0.1 Jun 21, 2023
2.0.1b0 Jun 20, 2023
2.0.0b0 Jun 19, 2023
1.1.7 Jun 06, 2023
1.1.6 Jun 05, 2023
1.1.5 Jun 03, 2023
1.1.4 May 23, 2023
1.1.3 May 01, 2023
1.1.2 Apr 19, 2023
1.1.1 Apr 18, 2023
1.1.0 Apr 18, 2023
1.0.3 Apr 17, 2023
1.0.2 Apr 17, 2023
1.0.1 Apr 16, 2023
1.0.0 Apr 16, 2023

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
anyio (<5.0.0,>=4.0.0)
typing-extensions (!=4.12.1)