{"id":15199943,"url":"https://github.com/maksimzayats/fastapi-better-di","last_synced_at":"2025-10-02T15:30:52.123Z","repository":{"id":40406209,"uuid":"482057809","full_name":"MaksimZayats/fastapi-better-di","owner":"MaksimZayats","description":"A utility that allows you to use DI in fastapi without Depends()","archived":true,"fork":false,"pushed_at":"2023-03-20T14:08:59.000Z","size":42,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-28T02:21:50.311Z","etag":null,"topics":["dependency-injection","di","fastapi","fastapi-dependency","fastapi-dependency-injection","fastapi-di","fastapidi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaksimZayats.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-04-15T19:01:47.000Z","updated_at":"2024-05-21T15:38:48.000Z","dependencies_parsed_at":"2023-12-05T07:23:18.340Z","dependency_job_id":"7f38b3e8-3fb5-41c1-ba49-5ea5f2efc57f","html_url":"https://github.com/MaksimZayats/fastapi-better-di","commit_stats":null,"previous_names":["maksimzayats/fastapi-better-di","maximzayats/fastapi-better-di"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksimZayats%2Ffastapi-better-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksimZayats%2Ffastapi-better-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksimZayats%2Ffastapi-better-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaksimZayats%2Ffastapi-better-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaksimZayats","download_url":"https://codeload.github.com/MaksimZayats/fastapi-better-di/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219875832,"owners_count":16554706,"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","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":["dependency-injection","di","fastapi","fastapi-dependency","fastapi-dependency-injection","fastapi-di","fastapidi"],"created_at":"2024-09-28T02:21:57.224Z","updated_at":"2025-10-02T15:30:51.750Z","avatar_url":"https://github.com/MaksimZayats.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastapi-better-di\n\n## What is this ?\n`fastapi-better-di` is a utility that allows you to use DI in fastapi without Depends()\n\n## Installation\n\n```shell\npip install fastapi_better_di\n```\n\n## Examples\n\n```python\n# app.py\nimport uvicorn\nfrom fastapi import FastAPI\nfrom fastapi_better_di.patcher.auto import is_pathed\n# functions were patched immediately after import\n\nassert is_pathed(), \"Something went wrong\"\n\n\nclass MyType:\n    def __init__(self, value):\n        self.value = value\n\n\napp = FastAPI()\napp.dependency_overrides[MyType] = lambda: MyType(123)\n\n\n@app.get(\"/\")\ndef handler(my_type: MyType):  # \u003c- DI without `Depends()`\n    assert my_type.value == 123\n    return my_type\n\n\nif __name__ == \"__main__\":\n    uvicorn.run(app)\n```\n\n[See all examples](examples)\n\n## Usage\n\n1. Patching:\n    * Auto patching: patches classes when importing:\n      ```python\n      from fastapi_better_di.patcher.auto import is_pathed # The classes were patched immediately after import\n\n      # To check if everything is OK, use assert\n      assert is_pathed(), \"Something went wrong\"\n      ```\n\n    * Manual patching: you need to call `patch()` by yourself:\n      ```python\n      from fastapi_better_di.patcher.manual import patch, is_pathed\n\n      patch()\n      \n      # To check if everything is OK, use assert\n      assert is_pathed(), \"Something went wrong\"\n      ```\n\n    * [Examples](examples)\n\n\n* **IMPORTANT**: You can still use `= Depends()` without a function as an argument,\n  and it won't add unnecessary arguments to the swagger.\n  * Related issue: [fastapi issue](https://github.com/tiangolo/fastapi/issues/4118)\n\n* **IMPORTANT**: The main app(`FastAPI`) and `dependency_overrides` must be initialized before importing routers!\n\n## How it works\n\n`fastapi-better-di` simply patch the handler function and add `= Depends(func)` as the default argument\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksimzayats%2Ffastapi-better-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaksimzayats%2Ffastapi-better-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksimzayats%2Ffastapi-better-di/lists"}