Metadata-Version: 2.1
Name: aioddd
Version: 1.3.5
Summary: Async Python DDD utilities library.
Author-email: ticdenis <denisnavarroalcaide@outlook.es>, yasti4 <adria_4_@hotmail.com>
Maintainer-email: ticdenis <denisnavarroalcaide@outlook.es>
License: MIT License        
        Copyright (c) 2020 - 2022 aiopy        
        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: documentation, https://aiopy.github.io/python-aioddd/
Project-URL: repository, https://github.com/aiopy/python-aioddd
Keywords: ddd,hexagonal,cqrs,aio,async
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: deploy
Requires-Dist: build (==0.8.0) ; extra == 'deploy'
Requires-Dist: setuptools (==62.3.2) ; extra == 'deploy'
Requires-Dist: twine (==4.0.1) ; extra == 'deploy'
Requires-Dist: wheel (==0.37.1) ; extra == 'deploy'
Provides-Extra: dev
Requires-Dist: pre-commit (==2.19.0) ; extra == 'dev'
Requires-Dist: tomli (==2.0.1) ; extra == 'dev'
Requires-Dist: types-backports (==0.1.3) ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs (==1.3.0) ; extra == 'docs'
Requires-Dist: mkdocs-material (==8.2.15) ; extra == 'docs'
Provides-Extra: fmt
Requires-Dist: black (==22.3.0) ; extra == 'fmt'
Requires-Dist: isort (==5.10.1) ; extra == 'fmt'
Provides-Extra: security-analysis
Requires-Dist: bandit (==1.7.4) ; extra == 'security-analysis'
Requires-Dist: liccheck (==0.7.1) ; extra == 'security-analysis'
Provides-Extra: static-analysis
Requires-Dist: mypy (==0.960) ; extra == 'static-analysis'
Requires-Dist: pylint (==2.14.0) ; extra == 'static-analysis'
Provides-Extra: test
Requires-Dist: nest-asyncio (==1.5.5) ; extra == 'test'
Requires-Dist: psutil (==5.9.1) ; extra == 'test'
Requires-Dist: pytest (==7.1.2) ; extra == 'test'
Requires-Dist: pytest-asyncio (==0.18.3) ; extra == 'test'
Requires-Dist: pytest-cov (==3.0.0) ; extra == 'test'
Requires-Dist: pytest-xdist (==2.5.0) ; extra == 'test'

# Async Python DDD utilities library

aioddd is an async Python DDD utilities library.

## Installation

Use the package manager [pip](https://pypi.org/project/aioddd/) to install aioddd.

```bash
pip install aioddd
```

## Documentation

- Visit [aioddd docs](https://aiopy.github.io/python-aioddd/).

## Usage

```python
from asyncio import get_event_loop
from dataclasses import dataclass
from typing import Type
from aioddd import NotFoundError, \
    Command, CommandHandler, SimpleCommandBus, \
    Query, QueryHandler, OptionalResponse, SimpleQueryBus, Event

_products = []

class ProductStored(Event):
    @dataclass
    class Attributes:
        ref: str

    attributes: Attributes

class StoreProductCommand(Command):
    def __init__(self, ref: str):
        self.ref = ref

class StoreProductCommandHandler(CommandHandler):
    def subscribed_to(self) -> Type[Command]:
        return StoreProductCommand

    async def handle(self, command: StoreProductCommand) -> None:
        _products.append(command.ref)

class ProductNotFoundError(NotFoundError):
    _code = 'product_not_found'
    _title = 'Product not found'

class FindProductQuery(Query):
    def __init__(self, ref: str):
        self.ref = ref

class FindProductQueryHandler(QueryHandler):
    def subscribed_to(self) -> Type[Query]:
        return FindProductQuery

    async def handle(self, query: FindProductQuery) -> OptionalResponse:
        if query.ref != '123':
            raise ProductNotFoundError.create(detail={'ref': query.ref})
        return {'ref': query.ref}

async def main() -> None:
    commands_bus = SimpleCommandBus([StoreProductCommandHandler()])
    await commands_bus.dispatch(StoreProductCommand('123'))
    query_bus = SimpleQueryBus([FindProductQueryHandler()])
    response = await query_bus.ask(FindProductQuery('123'))
    print(response)


if __name__ == '__main__':
    get_event_loop().run_until_complete(main())
```

## Requirements

- Python >= 3.7

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License

[MIT](https://github.com/aiopy/python-aioddd/blob/master/LICENSE)
