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.1.tar.gz (8.9 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.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for injex-0.1.1.tar.gz
Algorithm Hash digest
SHA256 901aa84ca74bf1e20cfcbb794a515e3b7cbf82e65ba33faebc6b5921f8e2a307
MD5 48da32a8a3c004f8f61befa323d3ae6f
BLAKE2b-256 af2e5cbd9eacf7288a581183b02b62600e1d547b09370ff35de5507b1e982777

See more details on using hashes here.

File details

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

File metadata

  • Download URL: injex-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f49023465695f92157dd855f3aa00b1fe3327a035a33b3fb6c9c78afc52db7
MD5 b608018363fb2a65693edebf449316cf
BLAKE2b-256 1211276615c05ae549e3bcc88163ddfc8865f002875bf005ce260d5439d9cc9d

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