Skip to main content

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

Metadata

Release files for aiobservable 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiobservable 0.2.2
File Size Uploaded Provenance
aiobservable-0.2.2.tar.gz 9.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiobservable 0.2.2
File Interpreter ABI Platform
aiobservable-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / aiobservable-0.2.2.tar.gz

Download URL aiobservable-0.2.2.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b42ad82b1e631362750f1c518c19b215ac34141e01c06c3510d3eef9236b8bd2
BLAKE2b-256 checksum
How to use checksums
e08b57a1cb44eb66dc10954bef0571d3a1caac1faea8632a7444631dc1536f4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

Release files / aiobservable-0.2.2-py3-none-any.whl

Download URL aiobservable-0.2.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00a282a90e918d5b57e88cbe97a3f8d5ae7847ac86d7e23135953bf464739171
BLAKE2b-256 checksum
How to use checksums
775151dd0fee247a915d9cd59dc66d20e39b36711e56b353236b334fa8ad357c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5

Security for aiobservable 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page