Metadata-Version: 2.3
Name: hdmi
Version: 0.2.0
Summary: A dependency injection framework for Python with dynamic late-binding resolution
Author: Romain Dorgueil
Author-email: Romain Dorgueil <romain@makersquad.fr>
License: MIT License
         
         Copyright (c) 2025 Romain Dorgueil
         
         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.
Requires-Dist: anyio>=4.0.0
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0 ; extra == 'dev'
Requires-Dist: ruff>=0.8.0 ; extra == 'dev'
Requires-Dist: basedpyright>=1.21.0 ; extra == 'dev'
Requires-Dist: sphinx>=8.0.0 ; extra == 'dev'
Requires-Dist: sphinx-autobuild>=2024.0.0 ; extra == 'dev'
Requires-Dist: furo>=2024.0.0 ; extra == 'dev'
Requires-Dist: sphinxcontrib-mermaid>=1.0.0 ; extra == 'dev'
Requires-Dist: twine>=6.0.0 ; extra == 'dev'
Requires-Python: >=3.13
Provides-Extra: dev
Description-Content-Type: text/markdown

# hdmi - Dependency Management Interface

> **Warning: Pre-Alpha Software**
>
> hdmi is experimental software in active development. Breaking changes may occur
> until version 1.0. Use with care in production environments.

A lightweight dependency injection framework for Python 3.13+ with:

- **Type-driven dependency discovery** - Uses Python's standard type annotations
- **Scope-aware validation** - Prevents lifetime bugs at build time
- **Lazy instantiation** - Services created just-in-time
- **Early error detection** - Configuration errors caught at build time

## Quick Example

### Simple Example (Singleton Services)

```python
import asyncio
from hdmi import ContainerBuilder

# Define your services
class DatabaseConnection:
    def __init__(self):
        self.connected = True

class UserRepository:
    def __init__(self, db: DatabaseConnection):
        self.db = db

class UserService:
    def __init__(self, repo: UserRepository):
        self.repo = repo

async def main():
    # Configure the container (all singletons by default)
    builder = ContainerBuilder()
    builder.register(DatabaseConnection)
    builder.register(UserRepository)
    builder.register(UserService)

    # Build validates the dependency graph
    container = builder.build()

    # Resolve services lazily - dependencies are auto-wired!
    user_service = await container.get(UserService)

asyncio.run(main())
```

### Using Scoped Services

```python
import asyncio
from hdmi import ContainerBuilder

async def main():
    # For request-scoped services (e.g., web requests)
    builder = ContainerBuilder()
    builder.register(DatabaseConnection)  # singleton (default)
    builder.register(UserRepository, scoped=True)  # One per request
    builder.register(UserService, transient=True)   # New each time

    container = builder.build()

    # Scoped services must be resolved within a scope context
    async with container.scope() as scoped:
        user_service = await scoped.get(UserService)
        # All scoped dependencies share the same instance within this scope

asyncio.run(main())
```

## Key Features

### Two-Phase Architecture

1. **ContainerBuilder** (Configuration): Register services and define scopes
2. **Container** (Runtime): Validated, immutable graph for lazy resolution

### Scope Safety

Services have four lifecycles that are validated at build time:

- **Singleton** (default): One instance per container
- **Scoped**: One instance per scope (e.g., per request)
- **Transient**: New instance every time
- **Scoped Transient**: New instance every time, requires scope

**Validation Rules (Simplified):**
The only invalid dependency is when a non-scoped service (singleton or transient) depends on a scoped service.

```python
# Valid: Scoped -> Singleton
builder = ContainerBuilder()
builder.register(DatabaseConnection)  # singleton (default)
builder.register(UserRepository, scoped=True)

# Invalid: Singleton -> Scoped (raises ScopeViolationError)
builder = ContainerBuilder()
builder.register(RequestHandler, scoped=True)
builder.register(SingletonService)  # singleton depends on scoped!
container = builder.build()  # ScopeViolationError!
```

### Type-Driven Dependencies

Dependencies are automatically discovered from type annotations:

```python
class ServiceA:
    def __init__(self, dep: DependencyType):
        self.dep = dep
```

No decorators or manual wiring required!

## Installation

```bash
pip install hdmi  # Coming soon
```

## Development

This project uses [uv](https://github.com/astral-sh/uv) for dependency management and follows strict TDD methodology.

```bash
# Run all checks (linting, type checking, tests)
make test

# Build documentation
make docs

# See all available commands
make help
```

## License

MIT License - see LICENSE file for details.
