Skip to main content
Pre-release

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 or None.
  • 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 of render_template: recovers placeholder values from a rendered payload, or None if 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; pass dp for single-DP ({dp}) topics, None for 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.3.0rc28

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

Built distributions (wheels)

Table of built distributions (wheels) for pyrustuyabridge 0.3.0rc28
File
pyrustuyabridge-0.3.0rc28-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 20.3 MB

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-win_amd64.whl

Download URL pyrustuyabridge-0.3.0rc28-cp39-abi3-win_amd64.whl
Size 2.6 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f4ca6a923812f8077b8deaffb266f36f7907f4ac57f8cab7b9c524a8d3c98e67
BLAKE2b-256 checksum
How to use checksums
50b2ff8c874ecdf3561421d2d396563ffd3b30559c63dfb7eeac130dbf1b9cd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL pyrustuyabridge-0.3.0rc28-cp39-abi3-musllinux_1_2_x86_64.whl
Size 3.3 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6a205ea1dd75249d930c802f1a193d6fe76d2f9a0a1c107f5846e12eaae3553c
BLAKE2b-256 checksum
How to use checksums
be8833692cebfa341a9efbe869525ad02b34d2f5b2002fdd05a4e61ecf096e27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL pyrustuyabridge-0.3.0rc28-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
959471f1114ff2eeed16aeecd0f1f6930ee1f145570a614d716a971f421eca54
BLAKE2b-256 checksum
How to use checksums
4256a308fd87deb246d9e128c08ecd83a97fed182d4f8691102e58d315a5f6a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pyrustuyabridge-0.3.0rc28-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
22fb1f1c625a78cf0299e78315c4e07e37a7de916f4b69a184382c9f17581448
BLAKE2b-256 checksum
How to use checksums
1fa6ef6d565284f1dc55807807e334051a865a5b7926d11df9dde472eb71fa22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL pyrustuyabridge-0.3.0rc28-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
c031a04e51d67c1d6688eb9bcce1c7d788fd71b212fa8ea71feed4c4e730a803
BLAKE2b-256 checksum
How to use checksums
9ca7c5c859b49645adc64d649bdef8f40c38b612feac4b5731ef94c4c5aaa9de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_11_0_arm64.whl

Download URL pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_11_0_arm64.whl
Size 2.7 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9e5e5aa120572cfa90e9035ff8ae09ba8f52f3da1be17ee24d5ef6881fdec6b7
BLAKE2b-256 checksum
How to use checksums
7f271d19cd4d5297bc3d01740f5ee1006a41d2660de09cf6dabaaea8b64fc7f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release files / pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_10_12_x86_64.whl

Download URL pyrustuyabridge-0.3.0rc28-cp39-abi3-macosx_10_12_x86_64.whl
Size 3.0 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6f477b1680820a2039298621cb8640df0f5e5a1ee2c0fe505eb534a2eff956b7
BLAKE2b-256 checksum
How to use checksums
811dcd00d27f28b075755e449c9fc6bc57a97b11cc0e7c567c7a014ae07d80c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 29, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

7 release files

This release

0.3.0rc28 This release

7 release files

0.1.4

7 release files

0.1.3

7 release files

0.1.2

7 release files

0.1.1

7 release files

0.1.0

7 release 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