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.1.1.tar.gz (21.2 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.1.1-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for inversipy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 708220d382baac34ff67f40a34426abd6b3ad195f10e834769df4c376caa4bc2
MD5 de16e3ca0f6f16b440e5dfad7c0739b7
BLAKE2b-256 35b3296ac82766db1d52ab5ffadb84c9d7a00549b2a56d34765cb9c9bcad4de2

See more details on using hashes here.

Provenance

The following attestation bundles were made for inversipy-0.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: inversipy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.0 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 360609b54e6ac18326f75e8f12bed26487120b95b237457578ad2fb7e82f92b7
MD5 46505645ba6a0591b31015a1e8c44796
BLAKE2b-256 527b6f32adb1b39a139ea76e4e1c8f240a4ea45faa0897d33c831ef808713b8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for inversipy-0.1.1-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