Skip to main content

Fostrom Device SDK

Project description

Fostrom Device SDK for Python

Fostrom is an IoT Cloud Platform built for developers. Monitor and control your fleet of devices, from microcontrollers to industrial IoT. Designed to be simple, secure, and fast. Experience first-class tooling with Device SDKs, type-safe schemas, programmable actions, and more.

The Fostrom Device SDK for Python works with Python 3.10+ and helps you quickly integrate, start monitoring, and controlling your IoT devices in just a few lines of code.

Installation

pip install fostrom

Quick Start

from fostrom import Fostrom, Mail

# Create SDK instance
fostrom = Fostrom({
    "fleet_id": "<your-fleet-id>",
    "device_id": "<your-device-id>",
    "device_secret": "<your-device-secret>",
    "env": "<dev|test|prod>",
})

# Setup mail handler for incoming messages
def handle_mail(mail: Mail):
    print(f"Received: {mail.name} ({mail.id})")
    mail.ack()  # Acknowledge the message

fostrom.on_mail = handle_mail

# Start the Device Agent and event stream
fostrom.start()

# Send sensor data
fostrom.send_datapoint("sensors", {
    "temperature": 23.5,
    "humidity": 65,
})

# Send status messages
fostrom.send_msg("status", {"online": True})

API Reference

Fostrom Class

__init__(config)

Create a new Fostrom instance.

Parameters:

  • config (dict): Configuration dictionary with:
    • fleet_id (str): Your fleet ID
    • device_id (str): Your device ID
    • device_secret (str): Your device secret
    • log (bool, default: True): Enable logging (default: True)
    • env (str, default: PYTHON_ENV || "dev"): Runtime Environment
    • stop_agent_on_exit (bool, default: False): If True, shutdown() will stop the Device Agent too.

start() -> None

Start the Device Agent in the background and connect to it.

shutdown(stop_agent: bool = False) -> None

Stop the background event processing. If stop_agent=True, also stops the Device Agent.

send_datapoint(name: str, payload: dict) -> None

Send a datapoint to Fostrom.

send_msg(name: str, payload: dict | None) -> None

Send a message to Fostrom. Pass None if the schema has no payload.

mailbox_status() -> dict

Get current mailbox status.

next_mail() -> Mail | None

Get the next mail from the mailbox.

Mail Class

Properties

  • id (str): Mail ID
  • name (str): Mail name/type
  • payload (dict): Mail payload data
  • mailbox_size (int): Current mailbox size

Methods

  • ack(): Acknowledge the mail
  • reject(): Reject the mail
  • requeue(): Requeue the mail

Device Agent

The Fostrom Device SDK downloads and runs the Fostrom Device Agent in the background. The Device Agent is downloaded automatically when the package is installed. The Device Agent starts when fostrom.start() is called and handles all communication with the Fostrom platform. The Device Agent runs continuously in the background, even after your Python program has terminated, to ensure that when your process manager restarts your Python program, it connects to the Device Agent right away. In case you want to stop the Device Agent when your program terminates, you can pass stop_agent_on_exit: True to the config.

Logging

The SDK logs via Python's logging module using the fostrom logger. By default, WARNING/ERROR/CRITICAL are visible; INFO is not.

To see INFO messages (e.g., "Connected"), enable logging:

import logging

logging.basicConfig(level=logging.INFO)

Links

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

fostrom-0.0.13.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

fostrom-0.0.13-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file fostrom-0.0.13.tar.gz.

File metadata

  • Download URL: fostrom-0.0.13.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for fostrom-0.0.13.tar.gz
Algorithm Hash digest
SHA256 df1ba873c34a1b711c1efc8aaf4c1ee02d22f0dc7b1be2f726302a00a1cf5a42
MD5 ee170fe693f0e9bef0833ff55c8c92d1
BLAKE2b-256 b1dcae7ef1e862228b425f4c0abb7b1e67d968096007ccd3775a6510181192d0

See more details on using hashes here.

File details

Details for the file fostrom-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: fostrom-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for fostrom-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 99d7ac6f7cd1b431d049b0a371623004ab91d8be07a50c417fa5580fda8b8bb6
MD5 83cc51066677b38aa8219025bbc5598b
BLAKE2b-256 787fd6c47ce4fd0f9a80f7570f80df8050faa21c2822597a0890243923c46c4f

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