Skip to main content

Python IOC Container

Project description


Python Inversion of Control (IoC) Container


pyioc3 is a lightweight and versatile Inversion of Control (IoC) container for Python. It simplifies the management of dependencies and enables cleaner, more modular code by promoting the use of Dependency Injection (DI) patterns. With pyioc3, you can effortlessly wire up your application's components, specify their lifecycles, and inject dependencies without the hassle of manual instantiation.

Key Features

Multiple APIs

pyioc3 offers multiple configuration interfaces including two manual configuration APIs and a decorator-based autowiring API. These APIs are flexible, yet simple to use.

Fluent Interface

pyioc3 manual APIs support method chaining to minimize boiler-plate code and intermediate variables.

Scoped Lifecycles

pyioc3 supports various scopes, including Singleton, Transient, and Requested. This provides fine-grained control of the lifecycle of your objects.


pyioc3 is an immutable ioc container that guarentees predictability of the dependency tree.

Constuctor Based DI

pyioc3 implements constructor based dependency injection making it easy to drop into existing applications.


pyioc3 pre-computes the dependency tree, resulting in fast instantiations to keep your code fast.

OOP Principles

pyioc3 is designed to improve the maintainability, testability, and flexibility of your Python applications.

Quick Start

Install the package

pip install --user pyioc3

StaticContainerBuilder API

from pyioc3 import StaticContainerBuilder

container = (
    .bind(QuackProvider, Squeak)

duck = container.get(Duck)

BuilderBase API

from pyioc3.builder import BuilderBase, ProviderBinding

class DuckBuilder(Duck):
    def __init__(self):

    def with_quack_noise(self, noise: str) -> "DuckBuilder":
            on_activate=lambda x: x.set_quack_noise(noise)
        return self

rubber_duck = (


Annotation API

from pyioc3.autowire import bind, AutoWireContainerBuilder

class QuackProvider:
    def quack(self):
        raise NotImplementedError()

class Duck:
    def __init__(self, quack: QuackProvider):
        self._quack = quack

    def quack(self):

class Squeak(QuackProvider):

    def quack(self):

duck = AutoWireContainerBuilder("my_package").build().get(Duck)

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

pyioc3-1.6.1.tar.gz (19.9 kB view hashes)

Uploaded source

Built Distribution

pyioc3-1.6.1-py3-none-any.whl (20.3 kB view hashes)

Uploaded py3

Supported by

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