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.2.tar.gz (9.1 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.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for injex-0.1.2.tar.gz
Algorithm Hash digest
SHA256 02e0bb333ca900ab98abe66ba619efc8d60fc4e362b5ffabc5c3a0f05858002e
MD5 de793ddaff11b78621e6c46fee5ce3ba
BLAKE2b-256 ec01b74e2ddaf19ead034a012417bafe0814561a5dfad9e1af6b346d16112b98

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for injex-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c69c65cd41f9f0ea64993c87f7a322d3f86a6e84e5c4913832654308ceae64dc
MD5 193ef7455df7c8adef8d1e3d5b000f68
BLAKE2b-256 2eb584083c1face423da719e301ef2e8b6de49dc5afd7845c8317ca8f2da87f6

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