Skip to main content

cangling-broker (Python)

Producer and consumer for cangling-broker. Same contract as the Java client: AcceptMessages to publish, Subscribe to consume, optional Register metadata, CL_BROKER_AUTH_TOKEN on every RPC.

Install

pip install cangling-broker

From this tree:

pip install -e python

Use

from cangling_broker import SatwayClient, SubscribeOptions

with SatwayClient.connect("127.0.0.1:7500", "change-me") as client:
    client.send("cangling-test", "hello")
    with client.subscribe(
        SubscribeOptions(topic="cangling-test", name="worker-1"),
        lambda message: print(message.id, message.payload),
    ):
        ...

SatwayClient.connect(broker) also reads CL_BROKER_AUTH_TOKEN from the environment.

Batch-set topic delivery (single = one consumer, broadcast = every live stream) and persistence (persistent = queue for later, ephemeral = drop if nobody is subscribed):

from cangling_broker import TopicConfig

client.configure_topics([
    TopicConfig("jobs", "single"),
    TopicConfig("alerts", "broadcast"),
    TopicConfig("live-events", "broadcast", "ephemeral"),
])
print(client.list_topics())

Existing Kafka senders can keep send(topic, value) / flush():

# from kafka import KafkaProducer
from cangling_broker import KafkaProducer

producer = KafkaProducer(bootstrap_servers="127.0.0.1:7500")
producer.send(topic, msg)
producer.flush()

Generic leader election

Every service can use the same application-defined election name. The auto-renewing handle fails closed when it cannot renew and exposes the monotonically increasing fencing term:

import os
from cangling_broker import SatwayClient

with SatwayClient.connect("cangling-broker:7500") as client:
    with client.start_election(
        "cis/algorithm-dispatcher",
        os.environ["HOSTNAME"],
        ttl_seconds=15,
    ) as election:
        if election.is_leader:
            dispatch_one_job(fencing_term=election.term)

Callbacks can be supplied with on_leader= and on_follower=, but they are notifications only. Check election.is_leader immediately before exclusive work and persist/pass election.term so downstream writers can reject a stale leader.

# consume
python python/examples/consumer.py --broker 127.0.0.1:7500 --topic cangling-test --name py-s0 --token change-me

# produce
python python/examples/producer.py --broker 127.0.0.1:7500 --topic cangling-test --text hello --count 1 --token change-me

Publish to PyPI

CI on tag v* builds the package and uploads with pypa/gh-action-pypi-publish. Set repository secret PYPI_API_TOKEN.

cd python
python generate_proto.py
python -m build

Metadata

Release files for cangling-broker 0.1.75

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

Source distribution (sdist)

Source distribution for cangling-broker 0.1.75
File Size Uploaded Provenance Actions
cangling_broker-0.1.75.tar.gz 19.2 kB Without provenance Details for cangling_broker-0.1.75.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cangling-broker 0.1.75
File Interpreter ABI Platform Actions
cangling_broker-0.1.75-py3-none-any.whl Python 3 none any Details for cangling_broker-0.1.75-py3-none-any.whl

Total release size: 38.4 kB

Release files / cangling_broker-0.1.75.tar.gz

Download URL cangling_broker-0.1.75.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
39b72632857bffe282d19127f225a5d5df4b657520cb2d652a9362e99a329351
BLAKE2b-256 checksum
How to use checksums
6cd2767b28c340550d0bb3e9f7e0f0dc990174c594085881adc9c277f2dba61d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / cangling_broker-0.1.75-py3-none-any.whl

Download URL cangling_broker-0.1.75-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
338f1a8d0a03bc48f07fa62fb1bfd0db7d0a92c0847e9b86bdf8a6046535e868
BLAKE2b-256 checksum
How to use checksums
87c43bb569de16aecb158bb1cf23afa9e52d5913c20aebdfbfac78097dc40464
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for cangling-broker 0.1.75

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.

Release history Release notifications | RSS feed

This release

0.1.75 This release

2 release files No provenance

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