Skip to main content

My Kafka PubSub Library

Wraps kafka into nice little simple classes
One for publishing pub and one for both publish and subscribe pubsub
The system transfers messages wrapped in an independent json format.
This is the structure of a sample envelope:

class TestEnvelope(Envelope):
    Identifier = "TestEnvelope"
    msg: str

    def __init__(self, msg: str = "", correlation_id: uuid.UUID = uuid.uuid4()):
        super().__init__(correlation_id)
        self.msg = msg

    def __str__(self):
        return f"msg:{self.msg}"

The envelope then needs to be registered with EnvelopeMapper.register(TestEnvelope.Identifier, TestEnvelope)
This allows the subscriber to correctly identify and deserialize the envelope
The correlation_id is passed through automatically with each message, but it is up to you to use correctly - i.e. Assign the same id to a response message, etc.

The pubsub class is the most complex, it has an internal thread that polls for messages and invokes the correct callback based on the envelope type.
The bindings are done as follows: pubsub.bind(TestEnvelope, callback)
Where the callback is a static function that looks like this: callback(pubsub, obj, context) pubsub is the instance that raised the callback, obj is the deserialized envelope, and context is whatever you passed into the context parameter in __init__()
This allows you to create specific bindings for each envelope type.
There is a catch-all binding pubsub.bind_everything(callback) that maps to everything that doesn't have a specific binding.

Note that all messages need to follow the envelope pattern, or they won't work at all.

The message pattern is so that it can be used language-agnostically - the same library exists in C#, and coexists with the python libraries.

Building

python -m build

Deploying

python -m twine upload --repository dist/*

Metadata

Release files for sb-pubsub-kafka 0.0.6

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

Source distribution (sdist)

Source distribution for sb-pubsub-kafka 0.0.6
File Size Uploaded Provenance
sb_pubsub_kafka-0.0.6.tar.gz 5.4 kB Without provenance Details

Release files / sb_pubsub_kafka-0.0.6.tar.gz

Download URL sb_pubsub_kafka-0.0.6.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
00bf1fbf7b7889e4ac72e7dcec089309b56860e1258d3694e7dbe65d042ccbae
BLAKE2b-256 checksum
How to use checksums
725d793ddd4713b51946476cfdd8472b98e40780e9c98cdd2690a1553656fa9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for sb-pubsub-kafka 0.0.6

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