skillfed

typer-injector

Dependency injection for typer

typer-injector v0.3.0 102.9K downloads/30d#12,839 on PyPI1
Permissive license MIT Active released

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-injector

uv

uv add typer-injector

poetry

poetry add typer-injector

Installing 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

Development Status :: 4 - BetaProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

typer dependency injectioncli dependency managementtyper command parametersfastapi-style cli injectionreusable cli dependenciestyper parameter sharingcli argument composition
cli-frameworkdependency-injectiontyper

More Application Frameworks packages