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.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

aioddd-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aioddd-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.3 Linux/5.3.0-1032-azure

File hashes

Hashes for aioddd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aa7554e04b3d2b9a16cd6092bcd1e5456dceb67c3b68de3ec34f02063f1eb3fa
MD5 4ff93facf2e1a7f7366263a3311c34cc
BLAKE2b-256 86c46c1c7452e1dbe8158039460841f9e587bdc0709c75e097a99200d0c528e7

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aioddd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.3 Linux/5.3.0-1032-azure

File hashes

Hashes for aioddd-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90b1884e45fe7a0ed1217702f6e9f82410c964c85207bfa09ea564114c5cb66
MD5 815a080880f58e15710d2b20ccab92c3
BLAKE2b-256 52f5dab9504592e888720f2a326580950a23893a6c7fb918099f7969d3aa7806

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