Skip to main content

FreshBlu Python SDK - Meshblu-compatible IoT messaging

Project description

freshblu

Python SDK for the FreshBlu IoT messaging platform. Meshblu-compatible.

Install

# HTTP only (uses urllib as fallback, or httpx if available)
pip install freshblu

# With httpx (recommended)
pip install freshblu[http]

# With WebSocket support
pip install freshblu[ws]

# Everything
pip install freshblu[all]

Requires Python 3.8+.

Quick Start

from freshblu import FreshBluHttp

client = FreshBluHttp("https://api.freshblu.org")

# Register a device
device = client.register({"type": "temperature-sensor"})
client.set_credentials(device["uuid"], device["token"])

# Send a message
client.message({
    "devices": ["target-uuid"],
    "payload": {"temp": 72.4}
})

# Get device info
me = client.whoami()

HTTP Client

from freshblu import FreshBluHttp

client = FreshBluHttp("https://api.freshblu.org")
# or
client = FreshBluHttp(hostname="api.freshblu.org", port=443, secure=True)

Works as a context manager:

with FreshBluHttp("https://api.freshblu.org") as client:
    device = client.register({"type": "sensor"})
    client.set_credentials(device["uuid"], device["token"])
    print(client.whoami())

Methods

Method Description
register(properties?) Register a new device. Returns dict with uuid and token.
whoami() Get authenticated device info.
get_device(uuid, as_uuid?) Get a device by UUID.
update_device(uuid, properties) Update device properties.
unregister(uuid) Delete a device.
search(query?) Search for devices.
my_devices() Get devices owned by the authenticated device.
claim_device(uuid) Claim an unclaimed device.
message(msg) Send a message ({"devices": [...], "payload": ...}).
broadcast(payload) Broadcast to all subscribers.
create_subscription(subscriber_uuid, emitter_uuid, type) Subscribe to events.
delete_subscription(subscriber_uuid, emitter_uuid, type) Remove a subscription.
subscriptions(subscriber_uuid) List subscriptions.
generate_token(uuid, expires_on?, tag?) Generate a new auth token.
revoke_token(uuid, token) Revoke a token.
reset_token(uuid) Revoke all tokens and return a new one.
status() Server health check (no auth required).
set_credentials(uuid, token) Set auth credentials.

WebSocket Client

Real-time messaging with event callbacks. Requires pip install freshblu[ws].

from freshblu import FreshBlu

client = FreshBlu("https://api.freshblu.org")

device = client.register({"type": "listener"})
client.set_credentials(device["uuid"], device["token"])

@client.on("message")
def on_message(data):
    print(f"From {data['fromUuid']}: {data['payload']}")

def on_ready():
    print("Connected!")

client.connect(callback=on_ready)

# Send over WebSocket
client.send_message({
    "devices": ["target-uuid"],
    "payload": {"hello": "world"}
})

The WebSocket runs in a background thread so it doesn't block your main program.

Async Client

For asyncio applications. Requires pip install freshblu[http].

import asyncio
from freshblu import AsyncFreshBlu

async def main():
    async with AsyncFreshBlu("https://api.freshblu.org") as client:
        device = await client.register({"type": "async-sensor"})
        client.set_credentials(device["uuid"], device["token"])

        me = await client.whoami()
        print(me)

asyncio.run(main())

Subscription Types

from freshblu import SubscriptionType

SubscriptionType.BROADCAST_SENT      # "broadcast.sent"
SubscriptionType.BROADCAST_RECEIVED  # "broadcast.received"
SubscriptionType.CONFIGURE_SENT      # "configure.sent"
SubscriptionType.CONFIGURE_RECEIVED  # "configure.received"
SubscriptionType.MESSAGE_SENT        # "message.sent"
SubscriptionType.MESSAGE_RECEIVED    # "message.received"
SubscriptionType.UNREGISTER_SENT     # "unregister.sent"
SubscriptionType.UNREGISTER_RECEIVED # "unregister.received"

Error Handling

from freshblu import FreshBluHttp, FreshBluError

client = FreshBluHttp("https://api.freshblu.org")

try:
    client.whoami()
except FreshBluError as e:
    print(f"Error: {e}")
    print(f"HTTP status: {e.status_code}")

Zero-Dependency Mode

The SDK works without any external packages using Python's built-in urllib. Install httpx for connection pooling, HTTP/2, and async support.

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

freshblu-1.0.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

freshblu-1.0.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for freshblu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 13c46d21c950e4d3bd42aae8e21ff2c8bc36c838c85bd610e57cc314625137c9
MD5 ef38edee8797ae9e09f2e15c97c60717
BLAKE2b-256 1b5c36d5e110dbbed7eb2b7a398f243cbdb51737ce5ca87236f605a5a3e642e6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for freshblu-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba82481aab1ef2702c73294466efaf71f01aa53b173a0bec1942772ebcf756f7
MD5 bb2076d54242e007c062333069ac0d86
BLAKE2b-256 b012a2a18d43289a957eaa2a148ffd009fdf443b4b8afa979cdaf9c5063b1f20

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