typer-injector
Dependency injection for typer
What it is and what it does
typer-injector bridges Typer CLI applications with FastAPI-style dependency injection, letting you define reusable parameter factories and inject them into commands via type annotations. Instead of repeating the same option parsing logic across multiple commands, you write a dependency function once and reference it by annotating parameters with Depends().
The package wraps Typer's InjectingTyper class and works with Typer's Option and Argument annotations. It's useful when your CLI has multiple commands that share common parameters—like database connections, configuration objects, or parsed composite arguments—that you want to define and validate in one place. The dependency system resolves these at command invocation time, similar to how FastAPI resolves dependencies for route handlers.
Use it for:
- Share parsed configuration (host, port, credentials) across multiple CLI commands without repeating option definitions.
- Build composite parameters from multiple CLI options—e.g., combine host and port into an Address tuple for reuse.
- Centralize validation logic for common parameter types across a multi-command CLI tool.
- Reduce boilerplate in CLI tools with many commands that accept overlapping sets of options.
- Organize CLI parameter handling using dependency injection patterns familiar from web frameworks.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds FastAPI-style dependency injection to Typer CLI applications, allowing you to define reusable parameter dependencies and inject them into multiple commands.
Yes, if you're building a Typer CLI with multiple commands that share parameters or need centralized dependency logic. The package is actively maintained, has low install friction, carries no security vulnerabilities, and uses a permissive MIT license. Start with it if you're already using Typer and find yourself repeating option definitions across commands.
Install
typer-injector on PyPI
pip
pip install typer-injectoruv
uv add typer-injectorpoetry
poetry add typer-injectorInstalling typer-injector
Before you install
Low friction installation with a single runtime dependency on typer. Actively maintained with recent commits and broad Python version support from 3.9 through 3.14.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
pip install typer-injector
import typer
from typer_injector import Depends, InjectingTyper
from typing import Annotated
app = InjectingTyper()
def my_dependency(value: str) -> str:
return value.upper()
Dep = Annotated[str, Depends(my_dependency)]
@app.command()
def my_command(dep: Dep) -> None:
print(dep)
Verify before relying
- Whether dependency caching or lifecycle management (request-scoped, singleton, etc.) is supported beyond the FastAPI pattern.
- Performance characteristics when many commands share complex dependency graphs.
- Compatibility with Typer's async command support.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typer |
| Maintenance | actively maintained — 107 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 102,870/month — #12,839 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: typer_injector-0.3.0-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
fastapi-injectableEnables FastAPI's Depends() dependency…
permissive · top 15,000 on PyPI
typer-cliThis package is a deprecated migration shim…
permissive · top 15,000 on PyPI
typer-configAdds configuration-file support to typer CLI…
permissive · top 15,000 on PyPI
typer-slimtyper-slim is a deprecated migration shim that…
permissive · top 5,000 on PyPI
taskiq-dependenciesProvides FastAPI-style dependency injection for…
unclear · top 5,000 on PyPI
sphinxcontrib-typerA Sphinx extension that auto-generates…
permissive · top 15,000 on PyPI
fast-dependsFastDepends provides a standalone dependency…
permissive · top 5,000 on PyPI
django-typerBuilds type-safe Django management command CLIs…
permissive · top 15,000 on PyPI
injectorInjector is a Python dependency injection…
permissive · top 5,000 on PyPI