Catalog PyPI
Back to packageRELEASE DETAILS

0.2.2

PyPI

aiobservable

# AIObservable [![PyPI](https://img.shields.io/pypi/v/aiobservable)][pypi-link] A simple and efficient implementation of the observable pattern. ## Introduction What sets it apart is that it doesn't represents events as a combination of a name and arguments, but instead operates on classes. Instead of using names like "on_connect" the library encourages the use of a "ConnectEvent" class which has the arguments as its attributes. Instead of listening to a meaningless name observers instead use the event type (the class). When emitting an event we then use instances of the event class. Apart from other benefits this especially helps with typings and eliminates the issue of having to know the f

Published2 Nov 2019
Direct dependencies0
Transitive dependenciesNot calculated

README

Version 0.2.2 documentation

AIObservable

PyPI

A simple and efficient implementation of the observable pattern.

Introduction

What sets it apart is that it doesn't represents events as a combination of a name and arguments, but instead operates on classes.

Instead of using names like "on_connect" the library encourages the use of a "ConnectEvent" class which has the arguments as its attributes. Instead of listening to a meaningless name observers instead use the event type (the class). When emitting an event we then use instances of the event class.

Apart from other benefits this especially helps with typings and eliminates the issue of having to know the function signature for each event, as the only argument is the event instance.

Using the built-in dataclasses makes it easy to avoid writing boiler-plate code for each event.

Example

import asyncio
import dataclasses

import aiobservable


@dataclasses.dataclass()
class ConnectEvent:
    user_id: int
    user_name: str

async def main():
    observable = aiobservable.Observable()

    def on_connect(event: ConnectEvent) -> None:
        print(f"{event.user_name} connected!")

    observable.on(ConnectEvent, on_connect)

    event = ConnectEvent(1, "Simon")

    # emit returns a future which resolves to None when all observers
    # are done handling the event
    await observable.emit(event)

asyncio.run(main())

Installing

You can install the library from PyPI:

pip install aiobservable

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

2 collected
aiobservable-0.2.2-py3-none-any.whl

bdist_wheel · 10.14 KB · Python py3

Source file
aiobservable-0.2.2.tar.gz

sdist · 8.77 KB · Python source

Source file

Repository

PENDING
gieseladev/aiobservable

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:41 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:6558d09116c1a204be5d1f591cd19174a059f95c4cfec756a6b7ed472331c6c8

Other collected versions

View all collected versions →