Catalog PyPI
PACKAGE EXPLORERView in registry

a13x-depinj

PyPI

A lightweight dependency injection framework for Python applications

containerdependencydiinjectionioc
Versions collected1
Direct dependencies6From release 0.2.0
Last observed20 Oct, 16:19 UTC

README

Version 0.2.0 documentation

a13x-depinj

A lightweight, yet powerful dependency injection framework for Python applications.

Features

  • Simple and intuitive API
  • YAML-based component configuration
  • Lazy component initialization
  • Automatic dependency management
  • Component lifecycle management
  • Type hints support
  • Context manager interface

Installation

pip install a13x-depinj

Quick Start

  1. Define your components:
from dataclasses import dataclass

@dataclass
class DatabaseConfig:
    url: str
    port: int

class Database:
    def __init__(self, config: dict):
        self.config = DatabaseConfig(**config)
        
    def connect(self):
        # Implementation
        pass

class UserService:
    def __init__(self, config: dict):
        self.db = ComponentRegistry().get(Database)
  1. Create a deployment configuration (deployment.yaml):
components:
  - module: myapp.database
    class: Database
    config_path: database.config
  - module: myapp.services
    class: UserService
    config_path: services.user

where config_path references a starting entry in the config.yaml file:

services:
    user:
        name: "a13x"
        email: "a13x.h.cc@gmail.com"

database:
    config:
        db_path: "data/market_data.db"
        enable_wal: true
        pragma_synchronous: "NORMAL"
        pragma_journal_mode: "WAL"
        pragma_cache_size: -2000  # 2MB cache
        max_connections: 10
  1. Initialize the registry:
from a13x_depinj import ComponentRegistry, Config

# Load application configuration
config = Config.load_config('config.yaml')

# Initialize components
with ComponentRegistry.from_yaml(config, 'deployment.yaml') as registry:
    # Get component instances
    db = registry.get(Database)
    user_service = registry.get(UserService)
    
    # Use components
    db.connect()

Advanced Usage

Lazy Initialization

Components can be initialized lazily when first accessed:

registry = ComponentRegistry.from_yaml(config, 'deployment.yaml', lazy=True)

Component Lifecycle Management

Components can implement cleanup methods:

class Database:
    def cleanup(self):
        # Cleanup resources
        pass

The registry will automatically call cleanup when using the context manager or when unregistering components.

Type Hints

The registry supports type hints for better IDE integration:

from typing import TypeVar, Type

T = TypeVar('T')
registry = ComponentRegistry[T]()
db: Database = registry.get(Database)

Contributing

Contributions are welcome! Please check our Contributing Guidelines for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.010 Mar 20256

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
a13xhv01/a13x-depinj

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 16:19 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:d0ea7c8058aa6f1ab42113781792d036d3d466605c63ba00a124ed0b7dec82ed