Diaspora Event Fabric SDK
Installation
pip install "diaspora-event-sdk[kafka-python]"
The kafka-python extra installs kafka-python, which the SDK's KafkaProducer and KafkaConsumer need. It accepts kafka-python>=2.1,<4: release 2.1 or a later 2.x, or any 3.x.
Moving to kafka-python 3
A new install of the extra gets kafka-python 3, which changes these defaults and names; the SDK keeps kafka-python's defaults:
KafkaProducerwaits for every in-sync replica (acksdefaults to -1,'all', where 2.x used 1) and is idempotent (enable_idempotencedefaults to True). Every topic has 2 replicas and the cluster'smin.insync.replicasis 2, so while a broker restarts the cluster refuses writes, and a send fails once itsdelivery_timeout_ms(120 s by default) has passed.kafka.errors.KafkaErrorsubclassesException, notRuntimeError, soexcept RuntimeErrorno longer catches it.kafka.errors.NoBrokersAvailableis gone.- A
key_serializer,value_serializer,key_deserializerorvalue_deserializerthat is a plain function makes kafka-python emit aDeprecationWarning(it still works); kafka-python 3 takes akafka.serializer.SerializerorDeserializer.
To keep 2.x's producer behaviour under kafka-python 3, pass acks=1, enable_idempotence=False to KafkaProducer, or pin kafka-python<3.
To use only the web service, including producing and consuming over REST, install the SDK without the extra:
pip install diaspora-event-sdk
Produce and consume over REST
The web service produces and consumes records over HTTPS with your Globus login, so a client needs no Kafka client and no access key. Client.produce and Client.produce_batch send records to the produce routes, which take the request bodies of Confluent's REST API v3. RESTConsumer wraps the consumer routes, which take the paths and bodies of Confluent REST Proxy v2 under /api/v2/consumers. Name topics and consumer groups without your namespace (Client().namespace): the service adds it, so the group my-group is the Kafka consumer group <namespace>.my-group.
from diaspora_event_sdk import Client, RESTConsumer
c = Client()
c.create_topic("my-topic")
c.produce("my-topic", {"step": 1, "loss": 0.52}, key="job-42")
c.produce_batch("my-topic", [{"value": {"step": 2}}, {"value": "done"}])
with RESTConsumer("my-group", client=c, format="json", auto_offset_reset="earliest") as consumer:
consumer.subscribe(["my-topic"])
for record in consumer.fetch(timeout_ms=5000):
print(record["offset"], record["key"], record["value"])
consumer.commit()
Client.produce writes a value of bytes as BINARY, and anything else, a str included, as JSON, which json.loads reads back the same as the SDK's KafkaProducer output: produce(topic, "done") writes the JSON string "done". The bytes differ, since the service writes compact JSON and KafkaProducer's default serializer adds spaces after , and :. That serializer also refuses bytes, which produce sends as BINARY. A key of bytes is sent as BINARY, a str as STRING (plain text), and anything else as JSON. The value_type and key_type arguments ("BINARY", "JSON" or "STRING") choose the type instead. Each record of Client.produce_batch is a dict of the same arguments (value, key, headers, timestamp, value_type and key_type) with an optional id.
A produce request is retried only when the service refuses it before sending the record (429 or 503) or when no connection was made. Any other error raises, since the record may have been written.
A consumer's format is binary, the default, or json. A binary consumer returns keys and values as bytes. A json consumer returns a key or value that is one JSON value as that value, and other text as str: a STRING key "42" comes back as the number 42. Header values are bytes in both formats.
The service drops consumer instances when it is deployed or restarted, and closes an instance idle for 5 minutes, which includes the time your code spends processing a fetch's records. RESTConsumer then creates the instance again with the same name and settings, subscribes or assigns as before, and retries the request once. The new instance starts from the group's committed offsets, so records fetched since the last commit can be fetched again. A commit() without offsets would commit the new instance's positions, which hold nothing fetched. So when the records fetched since the last commit came from an instance that is gone, whichever request found it gone, commit() sends nothing and raises CommitLostError, and the next fetch resumes at the group's last commit. A commit() with offsets on a new subscribed instance raises CommitLostError too: that instance gets its partitions at its first fetch, so commit the offsets again after a fetch.
RESTConsumer needs version 0.7.0 or later of the web service. The service's API reference gives every route, limit and error code.
Examples
- DiasporaDemo.ipynb — Authentication, user/key/topic management, and Kafka produce/consume
- ConsumerRESTDemo.ipynb — Produce and consume over REST, first with raw HTTP requests and then with the SDK
Acknowledgment
We thank the entire team of the Diaspora Project for their helpful comments and feedback. This material is based upon work supported by the U.S. Department of Energy (DOE), Office of Science, Office of Advanced Scientific Computing Research, under Contract DE-AC02-06CH11357.
License
This project is licensed under the Apache License 2.0.
Metadata
Release files for diaspora-event-sdk 0.5.0
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 |
|---|---|---|---|---|
| diaspora_event_sdk-0.5.0.tar.gz | 63.7 kB | With provenance | Details for diaspora_event_sdk-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diaspora_event_sdk-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for diaspora_event_sdk-0.5.0-py3-none-any.whl |
Total release size: 123.8 kB
Release files / diaspora_event_sdk-0.5.0.tar.gz
| Download URL | diaspora_event_sdk-0.5.0.tar.gz |
|---|---|
| Size | 63.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1760e9fbecc9b4c70507b3a3686abe6b50523a6f447793cec5d732ea4bd78ae5
|
|
BLAKE2b-256 checksum How to use checksums |
81618085d86bd75d1643c66484e3cdc22c92c745948154e09ae2c040ff80670e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / diaspora_event_sdk-0.5.0-py3-none-any.whl
| Download URL | diaspora_event_sdk-0.5.0-py3-none-any.whl |
|---|---|
| Size | 60.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1199ecfd8d90a9d2e87f3237ce6d51a8e5d178571b721ec9540d873faea4c275
|
|
BLAKE2b-256 checksum How to use checksums |
59ac4c7860aa6936f591035445158ca6ccb5b1a43c469085447675b6aec2b239
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for diaspora-event-sdk 0.5.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for diaspora_event_sdk-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA 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.