This release is a pre-release and may not be stable for production use.
pyrustuyabridge
Python bindings for rustuya-bridge, an MQTT bridge for managing Tuya devices via the Tuya Local API.
This package exposes the bridge server as an embeddable component, so Python code can run it alongside and interpret MQTT topics/payloads identically to the native bridge.
Install
pip install pyrustuyabridge
Pre-built wheels are provided for Linux (manylinux2014 / musllinux_1_2 on
x86_64 and aarch64), Windows x64, and macOS (x86_64 / arm64). Wheels are
built with PyO3 abi3-py39, so a single wheel per platform supports
CPython 3.9 and newer.
Quick start
import asyncio
from pyrustuyabridge import PyBridgeServer
async def main():
server = PyBridgeServer(
mqtt_broker="mqtt://localhost:1883",
mqtt_root_topic="rustuya",
)
await server.start_async()
asyncio.run(main())
Keeping the bridge running across reconfigure
The bridge is meant to be driven entirely over MQTT — including config changes.
To apply a change to the topic/payload templates or mqtt_retain, edit the
config_path file and publish a reconfigure action to the command topic. The
bridge clears the retained messages published under the old scheme and then
exits cleanly so the new config can take effect — exactly like the native
binary under systemd Restart=always.
In an embedded host there is no external supervisor, so wrap the server in a
small recreate loop. An intentional shutdown stops the supervisor (not the
bridge); any other exit — reconfigure or a crash — recreates it, re-reading
config_path:
# asyncio
import asyncio
from pyrustuyabridge import PyBridgeServer
class AsyncBridgeSupervisor:
def __init__(self, **kwargs):
self._kwargs = {**kwargs, "no_signals": True} # host owns signals
self._stop, self._server = False, None
async def run(self):
while not self._stop:
self._server = PyBridgeServer(**self._kwargs) # re-reads config_path
try:
await self._server.start_async() # returns on reconfigure/stop
except Exception as e:
print("bridge exited with error, restarting:", e)
await asyncio.sleep(5)
def stop(self):
self._stop = True
if self._server:
self._server.stop()
# asyncio.run(AsyncBridgeSupervisor(config_path="/etc/rustuya/config.json").run())
# thread
import threading, time
from pyrustuyabridge import PyBridgeServer
class BridgeSupervisor:
def __init__(self, **kwargs):
self._kwargs = {**kwargs, "no_signals": True}
self._stop = threading.Event()
self._server = None
def run(self): # run in a thread (blocking)
while not self._stop.is_set():
self._server = PyBridgeServer(**self._kwargs)
try:
self._server.start() # blocks until reconfigure/stop
except Exception as e:
print("bridge exited with error, restarting:", e)
time.sleep(5)
def stop(self):
self._stop.set()
if self._server:
self._server.stop()
Config precedence is kwargs > config_path file > defaults (the file only
fills fields left unset). So put any field you want to change via
reconfigure in the file, not in kwargs — a field passed as a kwarg wins
and the file edit is ignored (same rule as CLI flags vs. config file in the
native binary).
Helpers
The module also exposes topic/payload utilities for code that needs to match the bridge's wire format:
tpl_to_wildcard(template, root_topic)— template → MQTT wildcard.match_topic(topic, template)— returns extracted variables orNone.render_template(template, vars)— substitutes{key}placeholders.parse_payload(payload, vars)— parses an MQTT payload into a structured value.parse_payload_with_template(payload, template)— reverse ofrender_template: recovers placeholder values from a rendered payload, orNoneif not reversible.parse_seed_dps(payload, dp=None, template=None)— extracts the DPS map from an event payload exactly as the bridge's seed phase does; passdpfor single-DP ({dp}) topics,Nonefor multi-DP topics whose payload is the full DPS object.validate_payload_template(template)—(ok, message); checks whether a payload template can be reverse-parsed.
See the project repository for full documentation.
Release files for pyrustuyabridge 0.4.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_x86_64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ x86-64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_aarch64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ ARM64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 20.1 MB
Release files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-win_amd64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0bc0bd6d8043e3929f7ad8e65af36e5bd8b6c4aeb30c23544bff350f5952fbcb
|
|
BLAKE2b-256 checksum How to use checksums |
d5123f0ad973e78116714d82b954d3335103c9a96327ff9ef26c8088b5f9a4b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
391983bb94255d5b06772936a025bbc27e58b251a743bd66388bdc7b81f09338
|
|
BLAKE2b-256 checksum How to use checksums |
23ae134064046be6aa76fc35fe37e927d1b98f29ec00d33101a31fa51c495746
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
720cda6b641eae45157ccda73383c6e613b11173d7a7274ae342c167a37ac546
|
|
BLAKE2b-256 checksum How to use checksums |
1faf6ecf069eb979666ccaa22b7b6d7ff2faf83c1ebbc20a2fbde5f390fedac5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
88d3a0084847e58475e98fad52e65d06105b70d13f64b921473c5030ea95e23f
|
|
BLAKE2b-256 checksum How to use checksums |
da696a33c4c36ddcd8e853f263e2e3a2665afcfc1ac4d9f6d136c3e60bd489b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
009184b0054cb945aa15c137413cd5c754766c2739eb04e578f9275b9fef0fc5
|
|
BLAKE2b-256 checksum How to use checksums |
5ae9d2bf5fb230fde6266aac96535cc6958f8e72ffbd365e5b11c818a6234491
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e5c098d8681d537bdc41d9a1343512ae80df95f1858c0c9fca4fe1f732ba03b5
|
|
BLAKE2b-256 checksum How to use checksums |
403393fdf8487e5bfa9b767838c72c703740e75a7df2cc213973b80c1a1fef81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | pyrustuyabridge-0.4.0.dev0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4ba33caf2c6c0c6be377d4aee08fabcbc8b97400097b01aa20e8f6d91550f8e5
|
|
BLAKE2b-256 checksum How to use checksums |
372da75261e5341763bef24566161d35c6aaff2e1915941299a3cefff25f4654
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency log