skillfed

rodi

Implementation of dependency injection for Python 3

rodi v2.1.0 85.4K downloads/30d#13,925 on PyPI239
Permissive 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) Active released

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 rodi

uv

uv add rodi

poetry

poetry add rodi

Installing 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

Development Status :: 5 - Production/StableOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

dependency injection pythonservice container type hintsioc container pythondependency resolutiontype-based service registrationsingleton transient scoped servicespython di framework
dependency-injectionservice-containerioc

More Application Frameworks packages