Python SDK
PyPI package

The Fostrom Device SDK for Python is built to work on Linux and macOS. We test it across all architectures and operating systems we support. The minimum Python version required is 3.8.

Installation

You can install the package using pip:

pip install fostrom

We recommend using uv to manage your Python and pip installation and environment.

Usage

Since Python does not support running scripts at install time, the Fostrom Device Agent is downloaded the first time you run your program while importing the library. Note that you need to have either curl or wget installed on your system to download it.

from fostrom import Fostrom

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

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

# Attach the mail handler
fostrom.on_mail = handle_mail

# Connect to Fostrom
fostrom.connect()

# Send a Datapoint
fostrom.send_datapoint("<packet-schema-name>", {...payload})

# Send a Message
fostrom.send_msg("<packet-schema-name>", {...payload})

You can repeatedly read some sensor value in a loop and send the datapoint to Fostrom, or keep the program alive using a while True loop to process incoming mail.