This release is a pre-release and may not be stable for production use.
PyEnsign
PyEnsign is the official Python SDK for Ensign, a distributed event store and stream-processing platform. This library allows you to interact with the Ensign API directly from Python in order to create publishers and subscribers.
Installation
pip install pyensign
Usage
Create a client from a client ID and client secret. If not provided, these will be obtained from the ENSIGN_CLIENT_ID and ENSIGN_CLIENT_SECRET variables.
from pyensign.ensign import Ensign
client = Ensign(client_id=<your client ID>, client_secret=<your client secret>)
The Event class can be used to create events from the raw data and mimetype.
from pyensign.events import Event
event = Event(b'{"temp": 72, "units": "fahrenheit"}', "application/json")
Publish events to a topic. This coroutine accepts one or more events, so the following uses are all valid.
await client.publish("weather", event)
await client.publish("weather", event1, event2)
await client.publish("weather", [event1, event2])
Publish is asynchronous. You should generally call flush() before your program exits to ensure that all events are published to the server.
# Wait for events to be published with a default timeout of 2 seconds.
await client.flush()
For more precision, you can wait for individual events to be acked by the server.
ack = await event.wait_for_ack()
print(ack)
Subscribe to one or more topics by providing the topic name(s) or ID(s).
async for event in client.subscribe("weather"):
print("Received event with data: {}".format(event.data))
await event.ack()
Advanced Usage
The publish coroutine accepts asynchronous callbacks so the client can distinguish between committed and uncommitted events. Callbacks are invoked when acks and nacks are received from the server and the first argument passed to the callback is the Ack or Nack itself. An Ack contains a committed timestamp. A Nack is returned if the event couldn't be committed and contains the ID of the event along with an error describing what went wrong.
async def handle_ack(self, ack):
ts = datetime.fromtimestamp(ack.committed.seconds + ack.committed.nanos / 1e9)
print(f"Event committed at {ts}")
async def handle_nack(self, nack):
print(f"Could not commit event {nack.id} with error {nack.code}: {nack.error}")
await client.publish("weather", event, on_ack=handle_ack, on_nack=handle_nack)
Metadata
Release files for pyensign 0.12.1b0
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 | |
|---|---|---|---|---|
| pyensign-0.12.1b0.tar.gz | 61.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyensign-0.12.1b0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 127.1 kB
Release files / pyensign-0.12.1b0.tar.gz
| Download URL | pyensign-0.12.1b0.tar.gz |
|---|---|
| Size | 61.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
447d9852b184a719bcca04b9beac4861d5976f679adf8506b4ae7f121c3e4993
|
|
BLAKE2b-256 checksum How to use checksums |
28d33a4511add97e74b095163093f36c64e8f1c5c2845734894a84ec6b2b51bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / pyensign-0.12.1b0-py3-none-any.whl
| Download URL | pyensign-0.12.1b0-py3-none-any.whl |
|---|---|
| Size | 65.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49d166d7a5eed2d3d587a9a75894b4519f6656deda2e10f41aae1336ad53193a
|
|
BLAKE2b-256 checksum How to use checksums |
e0f8d4f26bc4356036d628d1f349f0b37716ce68ebf48478bc0c6d9e129563cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for pyensign 0.12.1b0
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.