Skip to main content

Python SDK for building Firmngin device integrations

Project description

Firmngin Python SDK

Firmngin Logo

Python License: MIT

Python SDK for Firmngin device clients, Raspberry Pi. Supports async and sync styles with mTLS, E2EE, entity state, payments, and optional image upload.

Docs: Introduction — Python SDK menu on firmngin.dev/docs

Install

pip install firmngin

Image upload (optional):

pip install firmngin[http]

From Git:

pip install git+https://github.com/firmngin/firmngin-sdk-python.git

Dependencies

Core install uses aiomqtt (MQTT) and cryptography (TLS + AES-GCM E2EE) only.

Client vs AsyncClient

| | AsyncClient | Client | | ---------- | ------------------------------- | ------------------------- | --- | | Style | async / await | Blocking calls | | | Push state | await client.push_entity(...) | client.push_entity(...) | | Event loop | await client.run() | client.run() |

Both use ClientConfig.from_file("keys.json") and support the same events.

Quickstart

from firmngin import Client, ClientConfig, Entity, EntityCommand

relay = Entity("relay")
temperature = Entity("temperature")

with Client(ClientConfig.from_file("keys.json")) as client:

    @client.on_entity(relay)
    def handle_relay(command: EntityCommand) -> None:
        print("relay:", command.value)

    client.connect()
    client.push_entity(temperature, 27.5)
    client.run()

Debug mode

Debug is off by default — no banner or console output.

client.set_debug(True)
client.connect()

With debug enabled, connect() prints the Firmngin banner, connection details, and connect/disconnect messages.

Events

Register handlers with client.on(Event.X, handler):

Event Payload Description
Event.PAYMENT Payment Payment updates
Event.PAYMENT_PENDING Payment Payment pending
Event.PAYMENT_SUCCESS Payment Payment succeeded
Event.INIT Init Device init payload
Event.MERCHANT_STATUS str Merchant status string
Event.VERIFICATION Verification Verification result
Event.PIN Verification PIN display
Event.DEVICE_STATUS DeviceStatus Device lifecycle
Event.ENTITY_COMMAND EntityCommand Any entity command
Event.ACTIVE_SESSION ActiveSession Active paid session
Event.METADATA_PENDING str Raw JSON from mop
Event.METADATA_EXPIRED str Raw JSON from moe
Event.METADATA_SUCCESS str Raw JSON from mos
Event.ERROR Exception Runtime error

Metadata events pass the decrypted payload as a JSON string — parse it in your handler.

import json

@client.on(Event.METADATA_PENDING)
def on_metadata(raw_json: str) -> None:
    data = json.loads(raw_json)

Per-entity commands:

@client.on_entity(Entity("relay"))
def on_relay(command: EntityCommand) -> None:
    print(command.value)

API overview

Import Role
AsyncClient Async device client
Client Sync blocking client
ClientConfig Runtime settings
KeysConfig keys.json loader
Event Event names for client.on(...)
Entity, Payment, Init, … Typed payloads

Device keys

Download keys.json from the Firmngin dashboard. The SDK accepts dashboard fields including server_fingerprint_bytes (20-byte Arduino-style fingerprint) and picks the right TLS validation mode automatically.

Never commit real keys. See keys.json.example.

Image upload

pip install firmngin[http]
await client.upload_image(Entity("camera"), "snapshot.jpg")

Examples

See examples/.

License

MIT — see LICENSE.

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

firmngin-0.0.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

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

firmngin-0.0.1-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file firmngin-0.0.1.tar.gz.

File metadata

  • Download URL: firmngin-0.0.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for firmngin-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b3483174ce0e59be50089d706b2723233c5d4a58ea1fe38a1339a5e500ad72ed
MD5 53f61094b917e7540828f810cc4e3dcb
BLAKE2b-256 e26f2b2f0f06d4ef47b768c81f6de090dc5379b3f4e97ee802d2f70a2c6ca26c

See more details on using hashes here.

File details

Details for the file firmngin-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: firmngin-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for firmngin-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b982742e37f2e490b5a27b528b56eab9cd0f755dedaddddfda95325697dc7af0
MD5 be9e0872eaaec0bd7d03ecb6134fd00c
BLAKE2b-256 f943b9b9018ec8679044ed03330009b3d9a14c53f27868113f3dc0410943808b

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