Skip to main content

Pure-Python Tuya mobile-app API signer, client, and MQTT signaling credentials (no native libs, no qemu)

Project description

tuya-mobile

Pure-Python reimplementation of Tuya's mobile-app API security layer — request signing (thing_security), the encrypted mobile API client, and the MQTT signaling credential derivation.

Tuya apps sign their mobile API requests with a native library (libthing_security.so). This package reimplements that algorithm in pure Python (HMAC-SHA256 / SHA256 / MD5 over ASCII) — so you can call the Tuya mobile API with no external signer service, no qemu, and no native .so.

It is generic across Tuya-based apps: only a handful of application constants differ per app (extracted from that app's APK). Supply them and it works.

What it provides

  • PurePythonTuyaSigner(app_id, app_secret, cert_sha256_hex, app_key, package)sign(canonical), derive_key(request_id, ecode), channel_key().
  • TuyaMobileClient(signer, session) — the encrypted mobile API flow (thing.m.user.third.login, signed/encrypted _call, local-key retrieval, cloud DP get/publish).
  • mqtt_credentials(signer, uid=…, ecode=…, partner_id=…) — MQTT broker username/password + signaling topics for the smart/mb channel.
  • mqtt_client_id(package) — isolated mobile-format client ID for a secondary client such as a local bridge.
  • NativeTuyaSigner — optional legacy fallback that shells out to an external signer (executable or HTTP), for parity/testing.

App credentials

The five app constants (app_id, app_secret, cert_sha256_hex, app_key, package) are the only app-specific inputs; the algorithm is identical across Tuya apps. This package intentionally ships no vendor credentials — the caller supplies them (e.g. petsseries supplies the Philips Pet Series values).

Usage

import aiohttp
from tuya_mobile import PurePythonTuyaSigner, TuyaMobileClient

signer = PurePythonTuyaSigner(
    app_id="…", app_secret="…", cert_sha256_hex="…", app_key="…",
    package="com.example.app",
)
async with aiohttp.ClientSession() as session:
    client = TuyaMobileClient(signer, session)
    await client.login_with_jwt(id_token, country_code="1", platform="…")
    status = await client.get_device_status(device_id)

License

MIT.

Project details


Download files

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

Source Distribution

tuya_mobile-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

tuya_mobile-1.0.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file tuya_mobile-1.0.0.tar.gz.

File metadata

  • Download URL: tuya_mobile-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tuya_mobile-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2f62968ce9cbe8cb6a01ecfdb5fc0cf40e61e513975c51506c5c2601433d9327
MD5 247338b7137085fd97d443fbcc8a9526
BLAKE2b-256 ec08e9eb2a6e138d011f39d522d3d1bf05abe2d89666216583d593724a105166

See more details on using hashes here.

File details

Details for the file tuya_mobile-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tuya_mobile-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tuya_mobile-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ba8d9ebeb767f3ccddb5f1ac636a27d0aba4762e653335f25508eaff6d9f002
MD5 4cf1ffc8439135a8f17b4d44fcc3135d
BLAKE2b-256 da5cdc5d5c26da8b25ebf0874aca4d99cff202aec5c5a8e133e5358d711693df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page