rodi
Implementation of dependency injection for Python 3
What it is and what it does
Rodi implements a dependency injection container that builds an object graph by inspecting type hints and class annotations at runtime, then generates efficient resolver functions to instantiate services on demand. It supports three service lifestyles: singleton (one instance per container), transient (new instance each time), and scoped (one instance per resolution call). The container is designed to be configured once at application startup and left unchanged during normal execution, making it suitable for web frameworks and other long-running applications.
The library operates without requiring changes to existing class source code—it reads constructor signatures and annotations to infer dependencies automatically. It validates the dependency graph when building resolver functions (detecting circular dependencies or missing services upfront), so runtime resolution has minimal overhead. Rodi offers both a generic protocol-based API for swappable DI implementations and a concrete implementation for direct use.
Use it for:
- Bootstrap a web application with centralized service registration and inject dependencies into request handlers
- Build a CLI tool that instantiates command handlers with their required services registered once at startup
- Create a plugin architecture where services are registered dynamically and resolved by type when plugins are loaded
- Manage database connections, loggers, and configuration objects as singletons across an application
- Test application code by registering mock or stub services in place of real implementations
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Rodi is a dependency injection container for Python that resolves and instantiates service dependencies based on type hints, class annotations, or configured names, supporting singleton, transient, and scoped lifestyles.
Yes. Rodi is actively maintained, has no external dependencies, supports modern Python versions (3.10+), carries a permissive MIT license, and solves a real problem for applications that need structured dependency management. It is particularly valuable in web frameworks and larger applications where service lifecycle management matters. No known security vulnerabilities.
Install
rodi on PyPI
pip
pip install rodiuv
uv add rodipoetry
poetry add rodiInstalling rodi
Before you install
Low friction install with no runtime dependencies. Active maintenance as of 2026-03-08 with 239 repository stars. Supports Python 3.10 through 3.14.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal restrictions—suitable for commercial and proprietary projects.
Quickstart
pip install rodi
from rodi import Container
container = Container()
container.register(MyService)
service = container.resolve(MyService)
Requires Python 3.10 or later.
Verify before relying
- Whether type resolution handles forward references and string annotations correctly
- Performance characteristics when resolving deeply nested dependency graphs
- Compatibility with async/await patterns in service initialization
Package facts
| License | MIT License Copyright (c) 2018 Roberto Prevato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 159 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 85,380/month — #13,925 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rodi-2.1.0-py3-none-any.whl
Keywords: dependency, hints, injection, type, typing
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
dependency-injectorDependency Injector is a dependency injection…
permissive · top 5,000 on PyPI
dishkadishka is an IoC container that manages…
permissive · top 15,000 on PyPI
punqPunq is a dependency injection container for…
unclear · top 15,000 on PyPI
wireupWireup is a type-driven dependency injection…
permissive · top 15,000 on PyPI
allukaAlluka is a type-based dependency injection…
permissive · top 15,000 on PyPI
simple-diA strictly typed dependency injection library…
permissive · top 15,000 on PyPI
slackA dependency injection container that registers…
permissive · top 15,000 on PyPI
lagomLagom is a lightweight dependency injection…
permissive · top 15,000 on PyPI
dependenciesImplements constructor injection for dependency…
permissive · top 15,000 on PyPI
taskiq-dependenciesProvides FastAPI-style dependency injection for…
unclear · top 5,000 on PyPI