eventkit-py
A toolkit for emitting and handling events, following the CloudEvent spec.
Installation
poetry add outcome-eventkit
Usage
It's a good idea to be familiar with the CloudEvent v1.0 spec before using this library.
The library implements the following (but is extensible):
Event Example
from outcome.eventkit import CloudEvent, CloudEventData
from outcome.eventkit.formats.json import JSONCloudEventFormat
from outcome.eventkit.protocol_bindings.http import StructuredHTTPBinding, BinaryHTTPBinding
import requests
# Create a payload, specifying how it will be encoded
data = CloudEventData(
data_content_type='application/json',
data={
'hello': 'world'
}
)
# Create an event
event = CloudEvent(type='co.outcome.events.sample', source='example', data=data)
# Create a JSON representation of the event
serialised_event = JSONCloudEventFormat.encode(event)
# Or...
# Create a HTTP message with the event
http_message = BinaryHTTPBinding.to_http(event)
# Or...
# Create a structured HTTP message with the event and a JSON formatter
http_message = StructuredHTTPBinding.to_http(event, JSONCloudEventFormat)
# Post the event somewhere...
requests.post('http://example.org', headers=http_message.headers, data=http_message.body)
Dispatch Example
from outcome.eventkit import dispatch, CloudEvent
# You can register event handlers that will be called
# when a corresponding event is dispatched
# Explicitly
def my_event_handler(event: CloudEvent) -> None:
...
# Register a handler for an event type
dispatch.register_handler('co.outcome.event', my_event_handler)
# Or via a decorator
@dispatch.handles_events('co.outcome.event', 'co.outcome.other-event')
def my_other_handler(event: CloudEvent) -> None:
...
# Then notify all registered handlers of an event
ev = CloudEvent(type='co.outcome.event', source='example')
dispatch.dispatch(ev)
By default, all handlers are stored in a single registry, but you can provide your own registry to the register_handler/handles_events/dispatch methods with the registry keyword argument.
from outcome.eventkit import dispatch
from collections import defaultdict
my_registry: dispatch.CloudEventHandlerRegistry = defaultdict(list)
@dispatch.handles_events('co.outcome.event', registry=my_registry)
def my_handler(event: CloudEvent) -> None:
...
ev = CloudEvent(type='co.outcome.event', source='example')
dispatch.dispatch(ev, registry=my_registry)
Development
Remember to run ./pre-commit.sh when you clone the repository.
Metadata
Release files for outcome-eventkit 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| outcome-eventkit-0.3.3.tar.gz | 11.3 kB | Without provenance | Details for outcome-eventkit-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| outcome_eventkit-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for outcome_eventkit-0.3.3-py3-none-any.whl |
Total release size: 25.5 kB
Release files / outcome-eventkit-0.3.3.tar.gz
| Download URL | outcome-eventkit-0.3.3.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a566a2782b1d68a5dd6f629a603c768031f35f29d4dc52bdebb434381bbc2d82
|
|
BLAKE2b-256 checksum How to use checksums |
8ef5335d90caff35a74d70f53aef7911074561eb12dcad4be6f12d71ebdcd182
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1040-azure
|
Release files / outcome_eventkit-0.3.3-py3-none-any.whl
| Download URL | outcome_eventkit-0.3.3-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49da3a084733b0ab41a236a62517578a7e7816a677665eafbe6ad85c57e57378
|
|
BLAKE2b-256 checksum How to use checksums |
52d3cc49a702da5c39cf2f7fd18f240d1e7a2ca3d3a0e8af5626fb9ad2351e23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1040-azure
|
Security for outcome-eventkit 0.3.3
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.