Python dependency injection libraries

Updated Nov 2026

Python dependency injection libraries supply the objects a class or function needs instead of letting it construct them itself. A container registers how to build each dependency and resolves the full graph when the application asks for an object. These libraries let developers swap databases, clients, and other services in tests without changing application code.

Popularity

Dependency Injector has the most monthly downloads in this comparison, at 11.0M.

LibraryMonthly downloadsStarsLast releaseLicense
Dependency Injector
11.0M
4.9KJun 2026MIT
Injector
3.9M
1.5KJan 2026BSD
svcs
3.0M
423Aug 2026MIT
Inject
2.9M
778Jul 2026Apache-2.0
FastDepends
2.3M
519Nov 2026MIT
Dishka
1.5M
1.3KApr 2026Apache-2.0
Lagom
447.1K
357Jul 2025MIT
Wireup
155.3K
442Nov 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Dependency Injector

Assembles application objects using explicit providers and containers.

Downloads / mo
11.0M
Stars
4.9K
Last release
4.49.1
License
MIT

Strengths

  • Replaces providers for tests. Override an API-client provider with a test stub.
  • Initializes and closes resources. Use Resource providers for components with startup and shutdown.

Limitations

  • Ordinary singletons need thread protection. Use ThreadSafeSingleton when multiple threads share a provider.
  • Function resources cannot define shutdown. Use a context manager or generator when cleanup is required.

Quickstart

From resource.py
$ python -m pip install dependency-injector==4.49.1
from dependency_injector import providers

service = providers.Factory(dict, message='hello')
print(service())

Dependency Injector examples

From open-source projects on GitHub

Resolves Python object dependencies through configured Injector instances.

Downloads / mo
3.9M
Stars
1.5K
Last release
0.24.0
License
BSD

Strengths

  • Uses separate container instances. Keep independent dependency configurations in separate Injector instances.
  • Offers custom lifetime scopes. Implement Scope.get to cache objects for a chosen lifetime.

Limitations

  • Provider work blocks other injections. Keep blocking I/O outside providers to avoid blocking other threads.
  • Automatic injection excludes ordinary methods. Use constructor injection rather than decorating other object methods.

Quickstart

From README.md
$ python -m pip install injector==0.24.0
from dataclasses import dataclass
from injector import Injector, inject
class Inner:
    def __init__(self):
        self.forty_two = 42

@inject
@dataclass
class Outer:
    inner: Inner

injector = Injector()
outer = injector.get(Outer)
print(outer.inner.forty_two)  # Prints 42

Injector examples

From open-source projects on GitHub
def create_application_injector() -> Injector:
    """Create a new injector with the default bindings."""
    _injector = Injector(auto_bind=True)
    _injector.binder.bind(Settings, to=unsafe_typed_settings)
    return _injector

Provides a service locator.

Downloads / mo
3.0M
Stars
423
Last release
26.2.0
License
MIT

Quickstart

From core-concepts.html
$ python -m pip install svcs==26.2.0
import svcs

with svcs.Registry() as registry:
    registry.register_value(str, 'hello')
    with svcs.Container(registry) as services:
        print(services.get(str))

svcs examples

From open-source projects on GitHub

Injects registered dependencies into parameters or attributes through a shared injector.

Downloads / mo
2.9M
Stars
778
Last release
5.5.0
License
Apache-2.0

Strengths

  • Reads parameter type annotations. Use autoparams to resolve annotated function dependencies.
  • Supports custom current-user providers. Bind a provider to return the current thread’s user.

Limitations

  • Implicit bindings create shared instances. Disable runtime bindings to require explicit registrations.
  • Configuration is shared. Use clear=True when replacing an existing configuration.

Quickstart

From README.md
$ python -m pip install inject==5.5.0
import inject

inject.configure(lambda binder: binder.bind(str, 'hello'))
print(inject.instance(str))

Inject examples

From open-source projects on GitHub

Runs the FastAPI dependency injection system outside HTTP code, with async and sync support.

Downloads / mo
2.3M
Stars
519
Last release
3.0.11
License
MIT

Quickstart

From use.py
$ python -m pip install "fast-depends[pydantic]==3.0.11"
from fast_depends import Depends, inject

def greeting() -> str:
    return 'hello'

@inject
def show(message: str = Depends(greeting)) -> str:
    return message

print(show())

FastDepends examples

From open-source projects on GitHub

Builds dependency graphs with scoped caches and resource finalization.

Downloads / mo
1.5M
Stars
1.3K
Last release
1.10.1
License
Apache-2.0

Strengths

  • Clears scoped dependency caches. Scope exit clears cached dependencies and finalizes generator factories.
  • Awaits asynchronous factories. Use an async container for synchronous and asynchronous dependency sources.

Limitations

  • Sync providers block async resolution. Keep network I/O out of synchronous providers in async containers.
  • Concurrent child scopes need locks. Pass a matching lock_factory for concurrently used nested scopes.

Quickstart

From README.md
$ python -m pip install dishka==1.10.1
from dishka import Provider, Scope, make_container

class Service:
    def __init__(self) -> None:
        self.message = 'hello'

provider = Provider(scope=Scope.APP)
provider.provide(Service)
container = make_container(provider)
print(container.get(Service).message)
container.close()

Dishka examples

From open-source projects on GitHub

Provides a dependency injection container that gives just enough help with building dependencies.

Downloads / mo
447.1K
Stars
357
Last release
2.7.7
License
MIT

Quickstart

From README.md
$ python -m pip install lagom==2.7.7
from lagom import Container

class Service:
    def __init__(self) -> None:
        self.message = 'hello'

container = Container()
print(container[Service].message)

Lagom examples

From open-source projects on GitHub

Provides dependency injection for Python.

Downloads / mo
155.3K
Stars
442
Last release
2.13.1
License
MIT

Quickstart

From README.md
$ python -m pip install wireup==2.13.1
import wireup

@wireup.injectable
class Service:
    def __init__(self) -> None:
        self.message = 'hello'

container = wireup.create_sync_container(injectables=[Service])
print(container.get(Service).message)

FAQ

Dependency Injector suits applications that want an explicit graph of providers and containers. Dishka suits applications that need nested scopes with cleanup of resources. svcs suits teams that prefer a typed service locator over automatic injection.

A container records how to build each service and passes the built objects into parameters or attributes that declare them. Without a library, applications pass dependencies by hand.

Dishka is a dependency injection framework that builds dependency graphs with scoped caches. Nested scopes finalize generator-based resources when they close.

Dependency Injector assembles application objects from explicit providers and containers, with module wiring to inject them.

For coding agents

Found your dependency injection library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official