{"id":49270350,"url":"https://github.com/modern-python/modern-di-typer","last_synced_at":"2026-07-01T22:01:29.726Z","repository":{"id":353763675,"uuid":"1220802447","full_name":"modern-python/modern-di-typer","owner":"modern-python","description":"modern-di integration for Typer","archived":false,"fork":false,"pushed_at":"2026-06-30T16:40:57.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-30T18:15:40.213Z","etag":null,"topics":["cli","dependency-injection","di","ioc-container","modern-di","python","typer"],"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":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-25T10:58:10.000Z","updated_at":"2026-06-30T16:41:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/modern-python/modern-di-typer","commit_stats":null,"previous_names":["modern-python/modern-di-typer"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/modern-python/modern-di-typer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di-typer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di-typer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di-typer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di-typer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modern-python","download_url":"https://codeload.github.com/modern-python/modern-di-typer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-python%2Fmodern-di-typer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35024365,"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":["cli","dependency-injection","di","ioc-container","modern-di","python","typer"],"created_at":"2026-04-25T13:22:09.281Z","updated_at":"2026-07-01T22:01:29.706Z","avatar_url":"https://github.com/modern-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"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-typer/lockup-dark.svg\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/modern-python/.github/main/brand/projects/modern-di-typer/lockup-light.svg\"\u003e\n    \u003cimg alt=\"modern-di-typer\" src=\"https://raw.githubusercontent.com/modern-python/.github/main/brand/projects/modern-di-typer/lockup.png\" width=\"420\"\u003e\n  \u003c/picture\u003e\n\u003c/p\u003e\n\n[![PyPI version](https://img.shields.io/pypi/v/modern-di-typer.svg)](https://pypi.org/project/modern-di-typer/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/modern-di-typer.svg)](https://pypi.org/project/modern-di-typer/)\n[![Downloads](https://static.pepy.tech/badge/modern-di-typer/month)](https://pepy.tech/projects/modern-di-typer)\n[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen.svg)](https://github.com/modern-python/modern-di-typer/actions/workflows/ci.yml)\n[![CI](https://github.com/modern-python/modern-di-typer/actions/workflows/ci.yml/badge.svg)](https://github.com/modern-python/modern-di-typer/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/modern-python/modern-di-typer.svg)](https://github.com/modern-python/modern-di-typer/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/modern-python/modern-di-typer)](https://github.com/modern-python/modern-di-typer/stargazers)\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[Modern-DI](https://github.com/modern-python/modern-di) integration for [Typer](https://typer.tiangolo.com).\n\n## Installation\n\n```bash\nuv add modern-di-typer      # or: pip install modern-di-typer\n```\n\n## Usage\n\n```python\nimport typing\nimport typer\nimport modern_di\nfrom modern_di import Scope, providers, Group\nfrom modern_di_typer import FromDI, inject, setup_di\n\n\nclass Dependencies(Group):\n    settings = providers.Factory(creator=lambda: {\"debug\": True})\n    service = providers.Factory(scope=Scope.REQUEST, creator=MyService, bound_type=None)\n\n\napp = typer.Typer()\ncontainer = modern_di.Container(groups=[Dependencies])\nsetup_di(app, container)\n\n\n@app.command()\n@inject\ndef my_command(\n    name: typing.Annotated[str, typer.Argument()],\n    service: typing.Annotated[MyService, FromDI(Dependencies.service)],\n) -\u003e None:\n    service.run(name)\n\n\nif __name__ == \"__main__\":\n    with container:\n        app()\n```\n\n## Action scope\n\n`Scope.ACTION` dependencies live below the per-command `Scope.REQUEST` container.\nOpen one with `action_scope(ctx)`: each `with` block yields a fresh action-scoped\ncontainer (a child of the command's request container), so you can open as many as\nyou need within a single command — one per item in a batch, for example.\n\n```python\nimport typer\nfrom modern_di import Scope, providers, Group\nfrom modern_di_typer import FromDI, action_scope, inject\n\n\nclass Dependencies(Group):\n    job = providers.Factory(scope=Scope.ACTION, creator=MyJob, bound_type=None)\n\n\n@app.command()\n@inject\ndef my_command(ctx: typer.Context) -\u003e None:\n    for job_name in job_names:\n        with action_scope(ctx) as action:\n            action.resolve_provider(Dependencies.job).run()\n```\n\n## API\n\n- `setup_di(app, container)` — register the container with a Typer app\n- `inject` — decorator that resolves `FromDI`-annotated parameters before the command runs; also exposes `typer.Context` with `ctx.obj[\"di_container\"]` for manual use\n- `FromDI(provider)` — marker used in `Annotated[T, FromDI(...)]`; accepts a provider instance or a type\n- `action_scope(ctx)` — context manager yielding a fresh `Scope.ACTION` container (a child of the command's request container); open one per action\n- `fetch_di_container(ctx)` — returns the app-scoped container from `ctx.obj`\n\n## Used by\n\n- **[semvertag](https://github.com/modern-python/semvertag)** — a CLI\n  auto-tagger for GitLab/GitHub that wires its settings, API providers, and\n  version-bump strategies through a `modern_di` container with\n  `modern-di-typer`. See\n  [`semvertag/ioc.py`](https://github.com/modern-python/semvertag/blob/main/semvertag/ioc.py)\n  for a real-world `setup_di` + `Group` setup.\n\n## 📦 [PyPI](https://pypi.org/project/modern-di-typer)\n\n## 📝 [License](LICENSE)\n\n## Part of `modern-python`\n\nBuilt on [`modern-di`](https://github.com/modern-python/modern-di), a dependency-injection framework with IoC container and scopes.\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-typer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodern-python%2Fmodern-di-typer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-python%2Fmodern-di-typer/lists"}