Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Rustuya

Crates.io Pypi.org Documentation License: MIT

Local-network control of Tuya-compatible devices, built in Rust with first-class Python bindings. Designed for fleets of hundreds to thousands of devices — a native Rust core handles the I/O while the Python facade releases the GIL on every blocking call, so threaded Python workers stay live.

Install

Rust

cargo add rustuya

Python

pip install rustuya

Quick start

Rust (sync)

use rustuya::sync::Device;

let dev = Device::new("DEVICE_ID", "LOCAL_KEY");
dev.set_value(1, true)?;                        // turn on DP 1
println!("{:?}", dev.status()?);                // read current DPS

for msg in dev.listener() {                     // real-time events
    println!("{:?}", msg);
}

Rust (async) — inside a tokio runtime

use rustuya::Device;
use futures_util::StreamExt;

#[tokio::main]
async fn main() -> Result<(), rustuya::TuyaError> {
    let dev = Device::new("DEVICE_ID", "LOCAL_KEY");
    dev.set_value(1, true).await?;              // turn on DP 1
    println!("{:?}", dev.status().await?);      // read current DPS

    let mut listener = dev.listener();
    while let Some(msg) = listener.next().await {   // real-time events
        println!("{:?}", msg);
    }
    Ok(())
}

Python

from rustuya import Device

dev = Device("DEVICE_ID", "LOCAL_KEY")
dev.set_value(1, True)                          # turn on DP 1
print(dev.status())                             # read current DPS

for msg in dev.listener():                      # real-time events
    print(msg)

Features

  • Local-only — talks directly to devices over LAN, no Tuya Cloud
  • Rust core + Python bindings (PyO3) — same engine for both
  • Built for fleet scale — per-device background tasks with automatic reconnection and exponential backoff
  • Full protocol coverage — Tuya 3.1 / 3.2 / 3.3 / 3.4 / 3.5 + device22

Tested at fleet scale

Large-scale behavior is exercised against real mock devices — a 1000-device tuyamock fleet with actual TCP connections and handshakes, not just unit mocks:

  • This repo stands up the 1000-device fleet and asserts every connection establishes without deadlock under a bounded connect-concurrency cap, in CI (python/tests/test_fleet_scale.py).
  • The downstream rustuya-bridge goes further end-to-end: a 1000-device fleet onboards cleanly with zero retained orphans after a mass clear, and a separate test holds the fleet idle for 30s to prove the heartbeat keeps every connection alive (witnessed mock-side) before fanning a single name-addressed command out to the whole fleet.

It proves the fleet machinery (bounded connect with no deadlock, heartbeat survival, fan-out) holds with 1000 concurrent devices over real sockets, end to end.

See the Guide for the full API reference, design philosophy, and architecture notes.

Credits

The Tuya protocol layer in rustuya is derived from the specifications and error codes documented in tinytuya:

License

MIT

Release files for rustuya 0.3.0rc10

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

Source distribution (sdist)

Source distribution for rustuya 0.3.0rc10
File Size Uploaded
rustuya-0.3.0rc10.tar.gz 96.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for rustuya 0.3.0rc10
File
rustuya-0.3.0rc10-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
rustuya-0.3.0rc10-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details

Total release size: 4.2 MB

Release files / rustuya-0.3.0rc10.tar.gz

Download URL rustuya-0.3.0rc10.tar.gz
Size 96.6 kB
Tags Source
SHA-256 checksum
How to use checksums
66437c39ca2f0b64533bd4929f119421756f15ce798e78cffdce6300aa427d79
BLAKE2b-256 checksum
How to use checksums
66aa29248fd1a1f0bd01b2e58f3c9cd350e0261dc6b881fe1fecb1f4f5c975ee
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 Jul 1, 2026.

Transparency log

Release files / rustuya-0.3.0rc10-cp38-abi3-win_amd64.whl

Download URL rustuya-0.3.0rc10-cp38-abi3-win_amd64.whl
Size 908.9 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
11dcb39316b5d9e5d2d8a73092c006b4e6784129d17c1a560797854f3c7b4f96
BLAKE2b-256 checksum
How to use checksums
595ae6fb176c130dcfd17dc84af1fbb0216ebc4d2877d36708ba6385b66faef9
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 Jul 1, 2026.

Transparency log

Release files / rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
cf0a40f3c8d94a854b5a00800ebbf3fc78a8462a2e8f0c2c0c833b33fda074dd
BLAKE2b-256 checksum
How to use checksums
032f01e8df691b849e316fa4d3eb23d4dab5a0f3519f7f25d32ac49223107b8e
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 Jul 1, 2026.

Transparency log

Release files / rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rustuya-0.3.0rc10-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.1 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
dc86516d3c0405e6173193098af2bd86754de0265ebecf5a2ff101d60b388f8c
BLAKE2b-256 checksum
How to use checksums
60af74e1261811565203479e30db9851b01de5fb6285db0049abefd50cb5ebc2
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 Jul 1, 2026.

Transparency log

Release files / rustuya-0.3.0rc10-cp38-abi3-macosx_11_0_arm64.whl

Download URL rustuya-0.3.0rc10-cp38-abi3-macosx_11_0_arm64.whl
Size 999.7 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3d6aa4329ed59f8ba99a6782647cd8c3f17fe903c056cbeff5710a4ce3ff702a
BLAKE2b-256 checksum
How to use checksums
7df3062a4657d23e176364fe97feeb1620468d7b2e78903ee86a4dc0783e99b5
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 Jul 1, 2026.

Transparency log
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