Python bindings for rustuyabridge — an MQTT bridge for Tuya devices
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dacc4e1e7ed66109aac3ff9f98d39d7db56c765a827d7b8384886017f17dc772
|
|
| MD5 |
ab4c4b23ac15e167a861b913db235c23
|
|
| BLAKE2b-256 |
7d89a2acabf1246785dcd1fa3933c6b7c464fce27e9473fc92df21261fc28479
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-win_amd64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-win_amd64.whl -
Subject digest:
dacc4e1e7ed66109aac3ff9f98d39d7db56c765a827d7b8384886017f17dc772 - Sigstore transparency entry: 1918378070
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0742e8860023607075bcda5dace2cf428f7c191f7705a16aec8805969ce59cd
|
|
| MD5 |
e6fcf6295845cb91591a56fda8dcd359
|
|
| BLAKE2b-256 |
18efe69a5c1ec50a8e85c55d7f551a432ccb8dd1f683e870ac69c84e38ad5938
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_x86_64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
d0742e8860023607075bcda5dace2cf428f7c191f7705a16aec8805969ce59cd - Sigstore transparency entry: 1918377608
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.9+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ffdac24e81315e3e3dc7f6ce8b0e28b97d691b208637bdd76f26c48009db442
|
|
| MD5 |
d223b58dd838fade5483ec6bd1e50b5b
|
|
| BLAKE2b-256 |
075584cc2ec9fa5d25ee7957fc8f89e8f2ccb3ac81060a63afe4e8ec9fac333c
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_aarch64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
4ffdac24e81315e3e3dc7f6ce8b0e28b97d691b208637bdd76f26c48009db442 - Sigstore transparency entry: 1918377944
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4e115fe70dd8754306a26834b146df35320997461c9eab9125cf460b11136d3
|
|
| MD5 |
73607ee9dac4f2155a9ba4fd4f940c66
|
|
| BLAKE2b-256 |
d44243a0b5973916ae31ce4ab926c0bfa3c294a0a3e5091d9188493cc5d67721
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
c4e115fe70dd8754306a26834b146df35320997461c9eab9125cf460b11136d3 - Sigstore transparency entry: 1918377495
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 2.8 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96a82fb50499e221aabd40793dd01dd039eb613de64d50cf1e8fd2734a399091
|
|
| MD5 |
c0132746fa9f44e2215f5446aa02decd
|
|
| BLAKE2b-256 |
b4c6b5c79acb4c2e6f606fc018f4f3859e7fe9dcf6577d8bbcc87c0535c22976
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
96a82fb50499e221aabd40793dd01dd039eb613de64d50cf1e8fd2734a399091 - Sigstore transparency entry: 1918377801
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad5c09e3555dd4cd231487b300e64c62e53d6f5d945235db38c72b2a2a561833
|
|
| MD5 |
8401e625732d8632b6859672c43f8631
|
|
| BLAKE2b-256 |
0b5ecaddedad2d344c40cdd4c922666c0d3e88e4fd4336558e76d2a34be946e9
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
ad5c09e3555dd4cd231487b300e64c62e53d6f5d945235db38c72b2a2a561833 - Sigstore transparency entry: 1918377713
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f8f85a4708aa1cc5cce169c66d2ca7f7b9953c450902674cb6f08e4846a60d8
|
|
| MD5 |
0b04a2dd1fa64e0717f12b8e910206cf
|
|
| BLAKE2b-256 |
0d00ea1d32b90e8ddacc2d95c203defeb92a129bfd50f925afc42619d946e5b7
|
Provenance
The following attestation bundles were made for pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
python-publish.yml on 3735943886/rustuya-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyrustuyabridge-0.3.0rc25-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
1f8f85a4708aa1cc5cce169c66d2ca7f7b9953c450902674cb6f08e4846a60d8 - Sigstore transparency entry: 1918378198
- Sigstore integration time:
-
Permalink:
3735943886/rustuya-bridge@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Branch / Tag:
refs/tags/py-v0.3.0-rc.25 - Owner: https://github.com/3735943886
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9984f899cdf479ef3e791d4c2a886f547f80e7a8 -
Trigger Event:
push
-
Statement type: