Skip to main content

DI container for Python applications

Project description

Build Status Python Versions License

DI Container for Python

Injex is a lightweight and easy-to-use DI container for Python applications. This library aims to simplify the management of dependencies in your projects, making your code more modular, testable, and maintainable. This library inspired by popular DI frameworks in other programming languages.

Features

  • 🌟 Simple API: Easy to understand and use.
  • 🔄 Support for singleton, transient, and scoped services.
  • Register multiple implementations of the same interface using names.
  • 🔍 Inject dependencies into properties after object creation.
  • 🛠 Handle optional dependencies gracefully.

Why Use Dependency Injection?

Dependency Injection is a design pattern that helps in:

  • Modularity: Breaking down your application into interchangeable components.
  • Testability: Facilitating unit testing by allowing dependencies to be mocked or stubbed.
  • Maintainability: Making it easier to update, replace, or refactor components without affecting other parts of the application.
  • Flexibility: Configuring different implementations of the same interface for various scenarios (e.g., testing, production).

Quick Start

Here's a simple example of usage Injex:

from abc import ABC, abstractmethod
from injex import Container

class IService(ABC):
    @abstractmethod
    def perform_action(self):
        pass

class ServiceImplementation(IService):
    def perform_action(self):
        print("Service is performing an action.")

container = Container()

container.add_transient(IService, ServiceImplementation)

service = container.resolve(IService)
service.perform_action() # output: Service is performing an action.

Another examples in examples folder.

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

injex-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

injex-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file injex-0.1.0.tar.gz.

File metadata

  • Download URL: injex-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.25

File hashes

Hashes for injex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5551e3b284ebb51c1a7b48552e74d04047dc782be99d22d16606bbcb584a23a
MD5 feacb5acfde7a5f4c2a2cd7b513df934
BLAKE2b-256 da4a2b5f6f10291bfdb2ae3211a0a0923673f196dc9000e05c5d1b91f705c2b5

See more details on using hashes here.

File details

Details for the file injex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: injex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.25

File hashes

Hashes for injex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9279ca527f233f095792ae9bcca9ca3a74d2115936758207cf1787de2a7ab3f
MD5 99272a79b53c55ec98da3c3de68a1de3
BLAKE2b-256 9b2247b229d8f4353dc8ec89c2fdd5884651779695175e96ea807f09ca23b4dd

See more details on using hashes here.

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