{"id":32964590,"url":"https://github.com/modern-python/modern-di","last_synced_at":"2026-07-01T20:00:43.662Z","repository":{"id":331618148,"uuid":"879368249","full_name":"modern-python/modern-di","owner":"modern-python","description":"Powerful dependency-injection framework with IoC container and scopes","archived":false,"fork":false,"pushed_at":"2026-06-30T16:27:23.000Z","size":1391,"stargazers_count":57,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-30T16:27:50.963Z","etag":null,"topics":["asyncio","dependency-injection","di","ioc","ioc-container","mocks","modern-di","python","scopes"],"latest_commit_sha":null,"homepage":"https://modern-di.modern-python.org","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/modern-python.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-27T18:08:41.000Z","updated_at":"2026-06-30T16:27:27.000Z","dependencies_parsed_at":"2026-03-06T18:06:25.019Z","dependency_job_id":null,"html_url":"https://github.com/modern-python/modern-di","commit_stats":null,"previous_names":["modern-python/modern-di"],"tags_count":109,"template":false,"template_full_name":null,"purl":"pkg:github/modern-python/modern-di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modern-python","download_url":"https://codeload.github.com/modern-python/modern-di/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35020872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"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":["asyncio","dependency-injection","di","ioc","ioc-container","mocks","modern-di","python","scopes"],"created_at":"2025-11-13T02:00:37.390Z","updated_at":"2026-07-01T20:00:43.657Z","avatar_url":"https://github.com/modern-python.png","language":"Python","funding_links":[],"categories":["Software","Third-Party Extensions","Dependency Injection"],"sub_categories":["DI Frameworks / Containers","Dependency Injection","General"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\"  srcset=\"https://raw.githubusercontent.com/modern-python/.github/main/brand/projects/modern-di/lockup-dark.svg\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/modern-python/.github/main/brand/projects/modern-di/lockup-light.svg\"\u003e\n    \u003cimg alt=\"modern-di\" src=\"https://raw.githubusercontent.com/modern-python/.github/main/brand/projects/modern-di/lockup.png\" width=\"420\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n[![GitHub stars](https://img.shields.io/github/stars/modern-python/modern-di)](https://github.com/modern-python/modern-di/stargazers)\n[![Context7](https://img.shields.io/badge/Context7-docs-blue)](https://context7.com/modern-python/modern-di)\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)\n\n| Project                                                                         | Badges                                                                                                                                                                                                                                                                   |\n|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| modern-di                                                                       | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di.svg)](https://pypi.python.org/pypi/modern-di ) [![downloads](https://static.pepy.tech/badge/modern-di/month)](https://pepy.tech/projects/modern-di)                                            |\n| [modern-di-fastapi](https://github.com/modern-python/modern-di-fastapi)         | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-fastapi.svg)](https://pypi.python.org/pypi/modern-di-fastapi) [![downloads](https://static.pepy.tech/badge/modern-di-fastapi/month)](https://pepy.tech/projects/modern-di-fastapi)             |\n| [modern-di-faststream  ](https://github.com/modern-python/modern-di-faststream) | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-faststream.svg)](https://pypi.python.org/pypi/modern-di-faststream) [![downloads](https://static.pepy.tech/badge/modern-di-faststream/month)](https://pepy.tech/projects/modern-di-faststream) |\n| [modern-di-litestar ](https://github.com/modern-python/modern-di-litestar)      | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-litestar.svg)](https://pypi.python.org/pypi/modern-di-litestar) [![downloads](https://static.pepy.tech/badge/modern-di-litestar/month)](https://pepy.tech/projects/modern-di-litestar)         |\n| [modern-di-typer](https://github.com/modern-python/modern-di-typer)            | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-typer.svg)](https://pypi.python.org/pypi/modern-di-typer) [![downloads](https://static.pepy.tech/badge/modern-di-typer/month)](https://pepy.tech/projects/modern-di-typer)                     |\n| [modern-di-pytest](https://github.com/modern-python/modern-di-pytest)          | [![Supported versions](https://img.shields.io/pypi/pyversions/modern-di-pytest.svg)](https://pypi.python.org/pypi/modern-di-pytest) [![downloads](https://static.pepy.tech/badge/modern-di-pytest/month)](https://pepy.tech/projects/modern-di-pytest)                 |\n\n`modern-di` is a python dependency injection framework which supports the following:\n\n- Automatic dependency graph based on type annotations\n- Also, explicit dependencies are allowed where needed\n- Scopes and context management\n- Python 3.10+ support\n- Fully typed and tested\n- Integrations with `FastAPI`, `FastStream`, `LiteStar` and `Typer`\n- Pytest integration (`modern-di-pytest`) — turns any DI dependency into a pytest fixture\n\n## Install\n\n```bash\nuv add modern-di      # or: pip install modern-di\n```\n\n## Quick Start\n\n```python\nimport dataclasses\nfrom modern_di import Container, Group, Scope, providers\n\n\n@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)\nclass Settings:\n    database_url: str = \"postgresql+asyncpg://localhost/app\"\n\n\n@dataclasses.dataclass(kw_only=True, slots=True)\nclass UserRepository:\n    settings: Settings  # auto-injected by type\n\n\nclass Dependencies(Group):\n    settings = providers.Factory(scope=Scope.APP, creator=Settings)\n    user_repository = providers.Factory(scope=Scope.REQUEST, creator=UserRepository)\n\n\nwith Container(groups=[Dependencies], validate=True) as container:\n    with container.build_child_container(scope=Scope.REQUEST) as request:\n        repo = request.resolve(UserRepository)\n        print(repo.settings.database_url)\n```\n\nSee the [documentation](https://modern-di.modern-python.org) for scopes, lifecycles, finalizers, and framework integrations.\n\nUsage examples:\n\n- with LiteStar - [litestar-sqlalchemy-template](https://github.com/modern-python/litestar-sqlalchemy-template)\n- with FastAPI - [fastapi-sqlalchemy-template](https://github.com/modern-python/fastapi-sqlalchemy-template)\n\n## 📚 [Documentation](https://modern-di.modern-python.org)\n\n## 📦 [PyPI](https://pypi.org/project/modern-di)\n\n## 📝 [License](LICENSE)\n\n## Part of `modern-python`\n\nBrowse the full list of templates and libraries in\n[`modern-python`](https://github.com/modern-python) — see the org profile for the categorized index.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-python%2Fmodern-di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodern-python%2Fmodern-di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-python%2Fmodern-di/lists"}