Skip to main content

Otensor Python SDK — para makers com hardware Linux/Raspberry Pi

Project description

otensor-sdk

PT-BR · SDK Python para makers com hardware Linux/Raspberry Pi — roda no dispositivo, publica telemetria e recebe comandos da plataforma Otensor.

EN · Python SDK for makers running Linux/Raspberry Pi hardware — runs on the device, publishes telemetry and receives commands from the Otensor platform.

Diferença em relação à lib de automação (pip install otensor):

otensor-sdk (este pacote) otensor
Onde roda No hardware (Raspberry Pi) Em qualquer lugar
O que faz Publica telemetria, recebe comandos Reage a eventos, cria automações

Instalação

pip install otensor-sdk

Requer Python ≥ 3.11.

Configuração

Gere uma API key no dashboard Otensor (as chaves começam com sk-) e cadastre um device do tipo sense_hat_unit (ou outro tipo do catálogo WoT).

API_BASE_URL=http://localhost:8000   # ou a URL real da sua instância
API_KEY=sk-...
DEVICE_ID=...

Início rápido

import os
from otensor_sdk import OtensorSDK

sdk = OtensorSDK(
    api_base_url=os.environ["API_BASE_URL"],
    api_key=os.environ["API_KEY"],
    device_id=os.environ["DEVICE_ID"],
)

device = sdk.connect(device_type="sense_hat_unit")  # já conecta ao MQTT

# publica uma leitura
device.publish_property("temperature", 24.5)

# recebe comandos da plataforma (registrar antes de qualquer publish, para
# não perder um comando que chegue entre o connect() e o registro)
@device.on_action("set_pixels")
def handle_set_pixels(payload: dict) -> None:
    print("acender LEDs:", payload)

Publicando telemetria em loop (TelemetryPublisher)

from otensor_sdk import TelemetryPublisher

publisher = TelemetryPublisher(device, interval=5.0)
publisher.set_source("temperature", lambda: sense_hat.get_temperature())
publisher.set_source("humidity", lambda: sense_hat.get_humidity())
publisher.run_forever()  # publica todas as sources a cada 5s, até Ctrl-C

Um exemplo completo, simulando um Raspberry Pi + Sense HAT sem hardware real, está em examples/mock_raspberry_pi.py.

Desenvolvimento

cd sdk-python
uv sync
uv run pytest tests/ -q                      # testes unitários (sem infra real)
RUN_E2E=1 uv run pytest tests/test_integration.py -v  # integração real (ver docstring do arquivo)

Processo de release (publicação no PyPI): ver RELEASING.md.

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

otensor_sdk-0.1.0.tar.gz (65.8 kB view details)

Uploaded Source

Built Distribution

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

otensor_sdk-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file otensor_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: otensor_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for otensor_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70c6fbb8da58111fa3813c7284e312e2258d2a2183baa3692fb19448e412f2d9
MD5 9ea130558b8e054ac3bb492ea1bee524
BLAKE2b-256 22e51959433e6a3c8d2f83d038709c5e90a13f88420d7b476b1a146015130386

See more details on using hashes here.

Provenance

The following attestation bundles were made for otensor_sdk-0.1.0.tar.gz:

Publisher: publish-sdk-python.yml on Oseiasdfarias/otensor-platform

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file otensor_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: otensor_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for otensor_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a47674e545bddae3d886ea28e82a2b347dc3ea4119023d48c8998f89359d04c
MD5 f84b629e9f6b61bc8fe4498cdb5d8607
BLAKE2b-256 45bf2f7d0d98145a6cce8ce3dc04c081c87e802abb7f55941fcee0d59531b5e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for otensor_sdk-0.1.0-py3-none-any.whl:

Publisher: publish-sdk-python.yml on Oseiasdfarias/otensor-platform

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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