Skip to content

inversipy

CI PyPI version Python versions License Coverage Docs

A powerful and type-safe dependency injection/IoC (Inversion of Control) library for Python 3.12+.

Why inversipy?

  • Zero runtime dependencies - Pure Python, nothing to install beyond the library itself
  • Type annotation-based - Dependencies resolved using Python type hints
  • Pure classes - No container coupling; classes remain framework-agnostic
  • Async-first - First-class support for async dependencies and factories
  • Validated - Catch configuration errors at startup, not at runtime

Key Features

Quick Example

from inversipy import Container, Scopes

class Database:
    def query(self, sql: str) -> list:
        return ["result"]

class UserRepository:
    def __init__(self, db: Database) -> None:
        self.db = db

    def get_users(self) -> list:
        return self.db.query("SELECT * FROM users")

class UserService:
    def __init__(self, repo: UserRepository) -> None:
        self.repo = repo

    def list_users(self) -> list:
        return self.repo.get_users()

# Create container and register dependencies
container = Container()
container.register(Database, scope=Scopes.SINGLETON)
container.register(UserRepository)
container.register(UserService)

# Validate and freeze
container.validate()
container.freeze()

# Resolve dependencies
service = container.get(UserService)
users = service.list_users()