Skip to main content

py-stinger-conn-iface

The interface for Python stinger connections.

This package defines the abstract, broker-agnostic interface that stinger-ipc broker connection implementations (e.g. MQTT) implement, along with the small set of value types (Message, ContentType) used to describe messages passing through that interface. It contains no broker-specific logic itself.

Supports Python 3.7+.

Installation

pip install py-stinger-conn-iface

Or, with uv:

uv add py-stinger-conn-iface

Contents

Message

A dataclass describing a single message to publish or that has been received.

from pystingerconniface import Message

msg = Message(topic="devices/123/status", payload=b'{"online": true}', qos=1, retain=True)
msg.set_user_property("trace-id", "abc123")
Field Type Description
topic str The topic the message is published to or received on.
payload bytes The raw message payload.
qos int The quality-of-service level for the message.
retain bool Whether the broker should retain the message on the topic.
content_type str | ContentType | None The content type of the payload, if any.
correlation_data bytes | None Correlation data for request/response patterns.
response_topic str | None Topic the receiver should reply to, if any.
subscription_ids list[int] Subscription identifiers a received message matched. Ignored on publish.
message_expiry_interval int | None Seconds after which the broker may discard the message.
user_properties dict[str, str] Arbitrary user-defined key/value metadata.

Message also converts to and from the shapes MQTT client libraries use. No client library is a dependency of this package: the inbound conversions are duck-typed, and paho_kwargs() imports paho-mqtt only when it is called.

# Publishing with paho-mqtt (requires paho-mqtt to be installed by the caller).
client.publish(**msg.paho_kwargs())

# Receiving, in a paho-mqtt on_message callback.
msg = Message.from_paho_message(paho_msg)
Method Description
mqtt_properties() The message's MQTT v5 PUBLISH properties as a dict keyed by their spec names (ContentType, UserProperty, ...). Unset properties are omitted.
set_mqtt_properties(properties) Applies such a dict onto the message. Unknown keys are ignored, so a client library's property object can be passed through as-is.
Message.from_mqtt_message(msg) Builds a Message from any received-message object with topic, payload, qos and retain attributes, plus an optional properties mapping or attribute carrier.
paho_kwargs() The keyword arguments for a paho-mqtt Client.publish() call, including a populated Properties object.
Message.from_paho_message(paho_msg) from_mqtt_message() under the name paho callers expect.

ContentType

A str subclass for parsing and constructing HTTP-style Content-Type header values, including their parameters (e.g. charset).

from pystingerconniface import ContentType

ct = ContentType("application/json; charset=utf-8")
ct == "application/json"          # True, ContentType is a str subclass
ct.parameters                     # {"charset": "utf-8"}
ct.charset                        # "utf-8" (also available as an attribute)
ct.to_header()                    # "application/json; charset=utf-8"

IBrokerConnection

An abstract base class describing the operations a broker connection implementation must provide: publishing messages, subscribing to topics, registering message callbacks, and reporting connection state.

from pystingerconniface import IBrokerConnection, Message

class MyBrokerConnection(IBrokerConnection):
    def publish(self, message: Message):
        ...

    def subscribe(self, topic, callback=None, qos=1):
        ...

    def add_message_callback(self, callback):
        ...

    def is_topic_sub(self, topic, sub):
        ...

    @property
    def online_topic(self):
        ...

    @property
    def client_id(self):
        ...

    def is_connected(self):
        ...

IBrokerConnection also provides a concrete unpublish_retained(topic) helper that publishes an empty, retained message to clear a previously retained message from a topic.

Development

This project uses uv for dependency management.

uv sync              # install runtime and dev dependencies
uv run pytest         # run the test suite
uv run ruff check .   # lint
uv run black .        # format
uv run mypy src tests # type check

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_stinger_conn_iface-0.1.1.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_stinger_conn_iface-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file py_stinger_conn_iface-0.1.1.tar.gz.

File metadata

  • Download URL: py_stinger_conn_iface-0.1.1.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for py_stinger_conn_iface-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e2e47efe08879e5610b6ad6d5adfa50e66963d6043534585c823f112460addf7
MD5 503b153d2e79b43c32dbb4b1ed9fe864
BLAKE2b-256 207847624acb8612b57d3739f7fc82cfa8d6e867417b46d268fc319d6a74ed77

See more details on using hashes here.

File details

Details for the file py_stinger_conn_iface-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_stinger_conn_iface-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for py_stinger_conn_iface-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0766d7e48bddf8c18ccfb026e20584025b1c1fead973791567bdd9821af4749d
MD5 9eec422f4f43fb73acac05597d0bf819
BLAKE2b-256 956bbc053db8398b58b175a99d390149c0a7855e540410e13aaf530bf3fa31af

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

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