{"id":15887838,"url":"https://github.com/lancetnik/fastdepends","last_synced_at":"2026-03-02T21:19:39.211Z","repository":{"id":153220365,"uuid":"628503532","full_name":"Lancetnik/FastDepends","owner":"Lancetnik","description":"FastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic. Async and sync modes are both supported.","archived":false,"fork":false,"pushed_at":"2025-08-26T05:03:09.000Z","size":655,"stargazers_count":412,"open_issues_count":15,"forks_count":25,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-08-26T07:05:53.491Z","etag":null,"topics":["async","dependency","dependency-injection","fastapi","faststream","propan","python","sync"],"latest_commit_sha":null,"homepage":"https://lancetnik.github.io/FastDepends/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lancetnik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"thanks_dev":"gh/lancetnik","custom":["https://pay.cloudtips.ru/p/0558c54a"]}},"created_at":"2023-04-16T06:27:58.000Z","updated_at":"2025-08-26T05:03:12.000Z","dependencies_parsed_at":"2023-11-12T09:24:59.218Z","dependency_job_id":"79815e59-494d-4133-bb39-1a77f5fcd68c","html_url":"https://github.com/Lancetnik/FastDepends","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/Lancetnik/FastDepends","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lancetnik%2FFastDepends","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lancetnik%2FFastDepends/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lancetnik%2FFastDepends/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lancetnik%2FFastDepends/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lancetnik","download_url":"https://codeload.github.com/Lancetnik/FastDepends/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lancetnik%2FFastDepends/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272467949,"owners_count":24939652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","dependency","dependency-injection","fastapi","faststream","propan","python","sync"],"created_at":"2024-10-06T06:05:16.773Z","updated_at":"2025-10-03T14:41:00.827Z","avatar_url":"https://github.com/Lancetnik.png","language":"Python","funding_links":["https://thanks.dev/gh/lancetnik","https://pay.cloudtips.ru/p/0558c54a"],"categories":[],"sub_categories":[],"readme":"# FastDepends\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Lancetnik/FastDepends/actions/workflows/tests.yml\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://github.com/Lancetnik/FastDepends/actions/workflows/tests.yml/badge.svg\" alt=\"Tests coverage\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://coverage-badge.samuelcolvin.workers.dev/redirect/lancetnik/fastdepends\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://coverage-badge.samuelcolvin.workers.dev/lancetnik/fastdepends.svg\" alt=\"Coverage\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/fast-depends\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/fast-depends?label=pypi%20package\" alt=\"Package version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pepy.tech/project/fast-depends\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://static.pepy.tech/personalized-badge/fast-depends?period=month\u0026units=international_system\u0026left_color=grey\u0026right_color=blue\" alt=\"downloads\"/\u003e\n    \u003c/a\u003e\n    \u003cbr/\u003e\n    \u003ca href=\"https://pypi.org/project/fast-depends\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/pypi/pyversions/fast-depends.svg\" alt=\"Supported Python versions\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Lancetnik/FastDepends/blob/main/LICENSE\" target=\"_blank\"\u003e\n        \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/Lancetnik/FastDepends?color=%23007ec6\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\nDocumentation: \u003chttps://lancetnik.github.io/FastDepends/\u003e\n\n---\n\nFastDepends - FastAPI Dependency Injection system extracted from FastAPI and cleared of all HTTP logic.\nThis is a small library which provides you with the ability to use lovely FastAPI interfaces in your own\nprojects or tools.\n\nThanks to [*fastapi*](https://fastapi.tiangolo.com/) and [*pydantic*](https://docs.pydantic.dev/) projects for this\ngreat functionality. This package is just a small change of the original FastAPI sources to provide DI functionality in a pure-Python way.\n\nAsync and sync modes are both supported.\n\n# For why?\n\nThis project should be extremely helpful to boost your not-**FastAPI** applications (even **Flask**, I know that u like some legacy).\n\nAlso the project can be a core of your own framework for anything. Actually, it was build for my another project - :rocket:[**Propan**](https://github.com/Lancetnik/Propan):rocket: (and [**FastStream**](https://github.com/airtai/faststream)), check it to see full-featured **FastDepends** usage example.\n\n## Installation\n\n```bash\npip install fast-depends\n```\n\n## Usage\n\nThere is no way to make Dependency Injection easier\n\nYou can use this library without any frameworks in both **sync** and **async** code.\n\n### Async code\n\n```python\nimport asyncio\n\nfrom fast_depends import inject, Depends\n\nasync def dependency(a: int) -\u003e int:\n    return a\n\n@inject\nasync def main(\n    a: int,\n    b: int,\n    c: int = Depends(dependency)\n) -\u003e float:\n    return a + b + c\n\nassert asyncio.run(main(\"1\", 2)) == 4.0\n```\n\n### Sync code\n\n```python\nfrom fast_depends import inject, Depends\n\ndef dependency(a: int) -\u003e int:\n    return a\n\n@inject\ndef main(\n    a: int,\n    b: int,\n    c: int = Depends(dependency)\n) -\u003e float:\n    return a + b + c\n\nassert main(\"1\", 2) == 4.0\n```\n\n`@inject` decorator plays multiple roles at the same time:\n\n* resolve *Depends* classes\n* cast types according to Python annotation\n* validate incoming parameters using *pydantic*\n\n---\n\n### Features\n\nSynchronous code is fully supported in this package: without any `async_to_sync`, `run_sync`, `syncify` or any other tricks.\n\nAlso, *FastDepends* casts functions' return values the same way, it can be very helpful in building your own tools.\n\nThese are two main defferences from native FastAPI DI System.\n\n---\n\n### Dependencies Overriding\n\nAlso, **FastDepends** can be used as a lightweight DI container. Using it, you can easily override basic dependencies with application startup or in tests.\n\n```python\nfrom typing import Annotated\n\nfrom fast_depends import Depends, dependency_provider, inject\n\ndef abc_func() -\u003e int:\n    raise NotImplementedError()\n\ndef real_func() -\u003e int:\n    return 1\n\n@inject\ndef func(\n    dependency: Annotated[int, Depends(abc_func)]\n) -\u003e int:\n    return dependency\n\nwith dependency_provider.scope(abc_func, real_func):\n    assert func() == 1\n```\n\n`dependency_provider` in this case is just a default container already declared in the library. But you can use your own the same way:\n\n```python\nfrom typing import Annotated\n\nfrom fast_depends import Depends, Provider, inject\n\nprovider = Provider()\n\ndef abc_func() -\u003e int:\n    raise NotImplementedError()\n\ndef real_func() -\u003e int:\n    return 1\n\n@inject(dependency_overrides_provider=provider)\ndef func(\n    dependency: Annotated[int, Depends(abc_func)]\n) -\u003e int:\n    return dependency\n\nwith provider.scope(abc_func, real_func):\n    assert func() == 1\n```\n\nThis way you can inherit the basic `Provider` class and define any extra logic you want!\n\n---\n\n### Custom Fields\n\nIf you wish to write your own FastAPI or another closely by architecture tool, you should define your own custom fields to specify application behavior.\n\nCustom 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.\n\nFastDepends grants you this opportunity a very intuitive and comfortable way.\n\n```python\nfrom fast_depends import inject\nfrom fast_depends.library import CustomField\n\nclass Header(CustomField):\n    def use(self, /, **kwargs: AnyDict) -\u003e AnyDict:\n        kwargs = super().use(**kwargs)\n        kwargs[self.param_name] = kwargs[\"headers\"][self.param_name]\n        return kwargs\n\n@inject\ndef my_func(header_field: int = Header()):\n    return header_field\n\nassert my_func(\n    headers={ \"header_field\": \"1\" }\n) == 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancetnik%2Ffastdepends","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flancetnik%2Ffastdepends","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flancetnik%2Ffastdepends/lists"}