Skip to main content

A powerful and type-safe dependency injection/IoC library for Python

Project description

inversipy

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

Features

  • Type annotation-based - Dependencies resolved using Python type hints
  • Pure classes - No container coupling; classes remain framework-agnostic
  • Zero runtime dependencies - Pure Python
  • Async-first - First-class support for async dependencies and factories
  • Module system - Organize dependencies with public/private access control
  • Multiple scopes - Singleton, Transient, and Request
  • Named dependencies - Multiple implementations with named disambiguation
  • Collection injection - Register and inject multiple implementations with InjectAll
  • Optional dependencies - T | None parameters resolve to None when unregistered
  • Container freezing - Lock the container after configuration
  • Validation - Catch configuration errors at startup
  • FastAPI integration - @inject decorator for route handlers
  • Full type safety - Strict MyPy support with py.typed marker

Installation

pip install inversipy

Quick Start

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()

Documentation

Full documentation is available at the documentation site.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Similar Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inversipy-0.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inversipy-0.2.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file inversipy-0.2.0.tar.gz.

File metadata

  • Download URL: inversipy-0.2.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inversipy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3eef225339ccfb3bc3009ca09ef7c98ffbe7993346b00ede001f187925b64acc
MD5 3d0c38122691fa3cc1ac317ac77957d5
BLAKE2b-256 ed2dea96f073a612ee42f54580c45479c06beaa7dddf61158505f7433b48dd19

See more details on using hashes here.

Provenance

The following attestation bundles were made for inversipy-0.2.0.tar.gz:

Publisher: publish.yml on mottetm/inversipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inversipy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: inversipy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inversipy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b21a4f1030031b5b9094ebf99cabaeec877ec1332b5bff93b09263ba7d0ea2a
MD5 e1825b96d94dcf15261b0c0bf316c267
BLAKE2b-256 e029e140734eb8c83520bfd8544d6a980c80869130571041ec0b3a9175b422be

See more details on using hashes here.

Provenance

The following attestation bundles were made for inversipy-0.2.0-py3-none-any.whl:

Publisher: publish.yml on mottetm/inversipy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page