Metadata-Version: 2.2
Name: a13x-depinj
Version: 0.2.0
Summary: A lightweight dependency injection framework for Python applications
Author: a13x-h
Author-email: a13x-h <a13x.h.cc@gmail.com>
License: MIT License
        
        Copyright (c) 2024 [a13x.h.cc@gmail.com]
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/a13xhv01/a13x-depinj.git
Project-URL: Documentation, https://github.com/a13xhv01/a13x-depinj.git#readme
Project-URL: Repository, https://github.com/a13xhv01/a13x-depinj.git
Project-URL: Bug Tracker, https://github.com/a13xhv01/a13x-depinj.git/issues
Keywords: dependency injection,di,ioc,container
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=8.3.4; extra == "dev"
Requires-Dist: pytest-cov>=6.0.0; extra == "dev"
Requires-Dist: black>=25.1.0; extra == "dev"
Requires-Dist: isort>=6.0.0; extra == "dev"
Requires-Dist: mypy>=1.15.0; extra == "dev"

# 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

```bash
pip install a13x-depinj
```

## Quick Start

1. Define your components:

```python
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)
```

2. Create a deployment configuration (deployment.yaml):

```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:

```yaml
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
```

3. Initialize the registry:

```python
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:

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

### Component Lifecycle Management

Components can implement cleanup methods:

```python
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:

```python
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](CONTRIBUTING.md) for details.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
