Skip to main content

Async Python DDD utilities library.

Project description

Async Python DDD utilities library

aioddd is an async Python DDD utilities library.

Installation

Use the package manager pip to install aiocli.

pip install aioddd

Usage

from asyncio import get_event_loop
from typing import Type
from aioddd import NotFoundError, \
    Command, CommandHandler, SimpleCommandBus, \
    Query, QueryHandler, OptionalResponse, SimpleQueryBus

_products = []

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.6

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aioddd-1.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

aioddd-1.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file aioddd-1.1.1.tar.gz.

File metadata

  • Download URL: aioddd-1.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.4.0-1025-azure

File hashes

Hashes for aioddd-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0a93f08d1c160a7061d64750691ccfbb173b5c6bb1fe8d3d5e00c0d837e27fd4
MD5 464748a7088000da926fb31a3f5146c4
BLAKE2b-256 41e34f132a3a20356a0989ce357a519c99f673635a508a6600d07ff61bcbffed

See more details on using hashes here.

Provenance

File details

Details for the file aioddd-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: aioddd-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.4.0-1025-azure

File hashes

Hashes for aioddd-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 243c563825ae166768c9a653a7689f4a1f56c42f3bd6af158259f6d568b80e1d
MD5 d623bd9c8287548fef4574300e41d1d6
BLAKE2b-256 8d1743d2d9d7686b89e58343e0c3bc08032b70a2fee8bb1a982a53ca4c4b7ca4

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page