bindry


Namebindry JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/hcleungca/bindry
SummaryElegant Python Dependency Injection with Profile-Aware Configuration
upload_time2024-11-26 02:15:20
maintainerNone
docs_urlNone
authorJason
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Bindry

Elegant Python Dependency Injection with Profile-Aware Configuration

[![PyPI version](https://badge.fury.io/py/bindry.svg)](https://badge.fury.io/py/bindry)
[![Python Support](https://img.shields.io/pypi/pyversions/bindry.svg)](https://pypi.org/project/bindry/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview

Bindry is a powerful yet intuitive dependency injection framework for Python that supports profile-based configuration, environment variable interpolation, and flexible component lifecycle management. It enables you to write more maintainable and testable applications by managing dependencies through configuration rather than hard-coding them.

## Features

- Profile-based configuration management
- Environment variable support with fallback values
- YAML and JSON configuration file support
- Constructor, method, and property injection
- Singleton and prototype scoping
- Type-based automatic dependency resolution
- Support for constructor arguments via configuration
- Flexible component registration through decorators or configuration files

## Installation

```bash
pip install bindry
```

## Quick Start

### 1. Define Your Components

```python
from bindry import component, Scope, autowired

# Define an interface
class MessageService:
    def send_message(self, msg: str): pass

# Implement the service
@component(scope=Scope.SINGLETON, bean_type=MessageService)
class EmailService(MessageService):
    def send_message(self, msg: str):
        print(f"Sending email: {msg}")

# Use dependency injection
@component(scope=Scope.SINGLETON)
class NotificationManager:
    @autowired
    def __init__(self, message_service: MessageService):
        self.message_service = message_service

    def notify(self, message: str):
        self.message_service.send_message(message)
```

### 2. Configure Your Application

Create a `config.yaml` file:

```yaml
profiles:
  default:
    beans:
      MessageService:
        bean_type: "myapp.services.MessageService"
        implementation: "myapp.services.EmailService"
        scope: "singleton"
        constructor_args:
          timeout: 30

  development:
    beans:
      MessageService:
        bean_type: "myapp.services.MessageService"
        implementation: "myapp.services.MockMessageService"
        scope: "prototype"
```

### 3. Initialize and Use

```python
from bindry import ApplicationContext

# Initialize the context
context = ApplicationContext.get_instance()
context.load_configuration("config.yaml", active_profiles=["development"])

# Get and use components
notification_manager = context.get_bean(NotificationManager)
notification_manager.notify("Hello, World!")
```

## Environment Variable Support

Bindry supports environment variable interpolation in configuration files:

```yaml
profiles:
  default:
    beans:
      DatabaseService:
        constructor_args:
          url: "${DATABASE_URL:sqlite:///default.db}"
          timeout: "${DB_TIMEOUT:30}"
```

## Profile Management

### Using Multiple Profiles

```python
context = ApplicationContext.get_instance()
context.set_active_profiles(["default", "development", "testing"])
```

### Environment-Based Profiles

Set the `ACTIVE_PROFILES` environment variable:

```bash
export ACTIVE_PROFILES=development,testing
```

## Advanced Features

### Constructor Argument Injection

```python
@component(
    scope=Scope.SINGLETON,
    constructor_args={
        "timeout": 30,
        "retries": 3,
        "kwargs": {"debug": True}
    }
)
class DatabaseService:
    def __init__(self, timeout: int, retries: int, **kwargs):
        self.timeout = timeout
        self.retries = retries
        self.debug = kwargs.get("debug", False)
```

### Method Injection

```python
@component(Scope.SINGLETON)
class ServiceManager:
    @autowired
    def configure(self, config_service: ConfigService):
        self.config_service = config_service
```

## Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

## License

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

## Acknowledgments

This project was developed with the assistance of AI language models:
- Initial implementation assistance provided by ChatGPT
- Additional feature development and refinements by Claude.ai

While the code was primarily generated through AI assistance, all implementations have been carefully reviewed and tested to ensure quality and reliability.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hcleungca/bindry",
    "name": "bindry",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jason",
    "author_email": "hcleung.ca+github@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/27/70dbe255cbf0f37516389f1a4afe54cd1a069c9043303ee2294717cd8ea1/bindry-0.1.0.tar.gz",
    "platform": null,
    "description": "# Bindry\r\n\r\nElegant Python Dependency Injection with Profile-Aware Configuration\r\n\r\n[![PyPI version](https://badge.fury.io/py/bindry.svg)](https://badge.fury.io/py/bindry)\r\n[![Python Support](https://img.shields.io/pypi/pyversions/bindry.svg)](https://pypi.org/project/bindry/)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n## Overview\r\n\r\nBindry is a powerful yet intuitive dependency injection framework for Python that supports profile-based configuration, environment variable interpolation, and flexible component lifecycle management. It enables you to write more maintainable and testable applications by managing dependencies through configuration rather than hard-coding them.\r\n\r\n## Features\r\n\r\n- Profile-based configuration management\r\n- Environment variable support with fallback values\r\n- YAML and JSON configuration file support\r\n- Constructor, method, and property injection\r\n- Singleton and prototype scoping\r\n- Type-based automatic dependency resolution\r\n- Support for constructor arguments via configuration\r\n- Flexible component registration through decorators or configuration files\r\n\r\n## Installation\r\n\r\n```bash\r\npip install bindry\r\n```\r\n\r\n## Quick Start\r\n\r\n### 1. Define Your Components\r\n\r\n```python\r\nfrom bindry import component, Scope, autowired\r\n\r\n# Define an interface\r\nclass MessageService:\r\n    def send_message(self, msg: str): pass\r\n\r\n# Implement the service\r\n@component(scope=Scope.SINGLETON, bean_type=MessageService)\r\nclass EmailService(MessageService):\r\n    def send_message(self, msg: str):\r\n        print(f\"Sending email: {msg}\")\r\n\r\n# Use dependency injection\r\n@component(scope=Scope.SINGLETON)\r\nclass NotificationManager:\r\n    @autowired\r\n    def __init__(self, message_service: MessageService):\r\n        self.message_service = message_service\r\n\r\n    def notify(self, message: str):\r\n        self.message_service.send_message(message)\r\n```\r\n\r\n### 2. Configure Your Application\r\n\r\nCreate a `config.yaml` file:\r\n\r\n```yaml\r\nprofiles:\r\n  default:\r\n    beans:\r\n      MessageService:\r\n        bean_type: \"myapp.services.MessageService\"\r\n        implementation: \"myapp.services.EmailService\"\r\n        scope: \"singleton\"\r\n        constructor_args:\r\n          timeout: 30\r\n\r\n  development:\r\n    beans:\r\n      MessageService:\r\n        bean_type: \"myapp.services.MessageService\"\r\n        implementation: \"myapp.services.MockMessageService\"\r\n        scope: \"prototype\"\r\n```\r\n\r\n### 3. Initialize and Use\r\n\r\n```python\r\nfrom bindry import ApplicationContext\r\n\r\n# Initialize the context\r\ncontext = ApplicationContext.get_instance()\r\ncontext.load_configuration(\"config.yaml\", active_profiles=[\"development\"])\r\n\r\n# Get and use components\r\nnotification_manager = context.get_bean(NotificationManager)\r\nnotification_manager.notify(\"Hello, World!\")\r\n```\r\n\r\n## Environment Variable Support\r\n\r\nBindry supports environment variable interpolation in configuration files:\r\n\r\n```yaml\r\nprofiles:\r\n  default:\r\n    beans:\r\n      DatabaseService:\r\n        constructor_args:\r\n          url: \"${DATABASE_URL:sqlite:///default.db}\"\r\n          timeout: \"${DB_TIMEOUT:30}\"\r\n```\r\n\r\n## Profile Management\r\n\r\n### Using Multiple Profiles\r\n\r\n```python\r\ncontext = ApplicationContext.get_instance()\r\ncontext.set_active_profiles([\"default\", \"development\", \"testing\"])\r\n```\r\n\r\n### Environment-Based Profiles\r\n\r\nSet the `ACTIVE_PROFILES` environment variable:\r\n\r\n```bash\r\nexport ACTIVE_PROFILES=development,testing\r\n```\r\n\r\n## Advanced Features\r\n\r\n### Constructor Argument Injection\r\n\r\n```python\r\n@component(\r\n    scope=Scope.SINGLETON,\r\n    constructor_args={\r\n        \"timeout\": 30,\r\n        \"retries\": 3,\r\n        \"kwargs\": {\"debug\": True}\r\n    }\r\n)\r\nclass DatabaseService:\r\n    def __init__(self, timeout: int, retries: int, **kwargs):\r\n        self.timeout = timeout\r\n        self.retries = retries\r\n        self.debug = kwargs.get(\"debug\", False)\r\n```\r\n\r\n### Method Injection\r\n\r\n```python\r\n@component(Scope.SINGLETON)\r\nclass ServiceManager:\r\n    @autowired\r\n    def configure(self, config_service: ConfigService):\r\n        self.config_service = config_service\r\n```\r\n\r\n## Contributing\r\n\r\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Acknowledgments\r\n\r\nThis project was developed with the assistance of AI language models:\r\n- Initial implementation assistance provided by ChatGPT\r\n- Additional feature development and refinements by Claude.ai\r\n\r\nWhile the code was primarily generated through AI assistance, all implementations have been carefully reviewed and tested to ensure quality and reliability.\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Elegant Python Dependency Injection with Profile-Aware Configuration",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/hcleungca/bindry/issues",
        "Documentation": "https://bindry.readthedocs.io/",
        "Homepage": "https://github.com/hcleungca/bindry"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2e2ed407856dc801b33179dd01a0c946ab27cf0703208345fdc77d85522f4d9",
                "md5": "14fac5111db8d99b53e6937e86416d03",
                "sha256": "4f281151a9d0ecff71551d7d0986319179a1abf018f1636394ca3bc1f96a903b"
            },
            "downloads": -1,
            "filename": "bindry-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "14fac5111db8d99b53e6937e86416d03",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13617,
            "upload_time": "2024-11-26T02:15:18",
            "upload_time_iso_8601": "2024-11-26T02:15:18.930949Z",
            "url": "https://files.pythonhosted.org/packages/c2/e2/ed407856dc801b33179dd01a0c946ab27cf0703208345fdc77d85522f4d9/bindry-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b2770dbe255cbf0f37516389f1a4afe54cd1a069c9043303ee2294717cd8ea1",
                "md5": "4711b3ae2cc0dd3d25b8db3a184f1c23",
                "sha256": "911ecc6242053df6c0345d19735f13d8eec5301ea386f8f9eca4c3888011bee7"
            },
            "downloads": -1,
            "filename": "bindry-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4711b3ae2cc0dd3d25b8db3a184f1c23",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 53013,
            "upload_time": "2024-11-26T02:15:20",
            "upload_time_iso_8601": "2024-11-26T02:15:20.780689Z",
            "url": "https://files.pythonhosted.org/packages/2b/27/70dbe255cbf0f37516389f1a4afe54cd1a069c9043303ee2294717cd8ea1/bindry-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-26 02:15:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hcleungca",
    "github_project": "bindry",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "bindry"
}
        
Elapsed time: 0.39490s