Skip to main content

cloudpostoffice

Python SDK for CloudPostOffice — super-simple messaging for AI agents, apps, and IoT devices.

Install

pip install cloudpostoffice

Quick start

Each app or device needs a unique postbox ID and a secret key. Create them from your dashboard. Two clients cannot connect with the same postbox ID at the same time — every participant needs its own credentials.


Direct Messages

Send a message directly from one postbox to another.

import asyncio
import cloudpostoffice as cpo

p1 = cpo.postbox('proj-xxx--postbox-1', 'your-secret')
p2 = cpo.postbox('proj-xxx--postbox-2', 'your-secret')

async def main():
    def on_message(msg):
        print(msg)  # { 'from': 'proj-xxx--postbox-1', 'msg': 'hello', 'ts': 1234567890 }

    # postbox-2 listens for incoming messages
    await p2.listen(on_message)

    # postbox-1 sends a message to postbox-2
    await p1.send(to='proj-xxx--postbox-2', msg='hello')

asyncio.run(main())

The listen callback receives a dict { 'from', 'msg', 'ts' } where from is the sender's postbox ID, msg is the payload, and ts is the server timestamp.


Pub/Sub

Any postbox can publish or subscribe to any topic in the same project. No need to pre-create topics — they work on the fly.

import asyncio
import cloudpostoffice as cpo

p1 = cpo.postbox('proj-xxx--postbox-1', 'your-secret')
p2 = cpo.postbox('proj-xxx--postbox-2', 'your-secret')

async def main():
    def on_news(topic, msg):
        print(topic, msg)

    # p1 subscribes to a topic
    await p1.subscribe('news', on_news)

    # p2 publishes to the same topic
    await p2.publish('news', 'CloudPostOffice is live!')

asyncio.run(main())

The subscribe callback receives (topic_name, message).


API

cpo.postbox(postbox_id, postbox_secret)

Creates a postbox handle. Automatically authenticates and connects to the MQTT broker on first use.

p = cpo.postbox('proj-xxx--postbox-1', 'my-secret')

await postbox.send(to, msg)

Sends a direct message to another postbox on the same account/project.

Param Type Description
to str Target postbox ID
msg any Message payload (any JSON-serialisable value)
await p1.send(to='proj-xxx--postbox-2', msg='hello')

await postbox.listen(callback)

Registers a callback for messages addressed to this postbox. Can be called multiple times to add multiple handlers.

def on_message(msg):
    print(f"Message from {msg['from']}:", msg['msg'])

await p.listen(on_message)

await postbox.publish(topic_name, message)

Publishes a message to a named topic.

  • Topic names must not contain /, +, #, or --.
await p.publish('alerts', {'level': 'warn', 'text': 'High temp'})

await postbox.subscribe(topic_name, callback)

Subscribes to a named topic. Callback is called whenever a message is published to that topic.

def on_alert(topic, msg):
    print(topic, msg)

await p.subscribe('alerts', on_alert)

postbox.disconnect()

Gracefully closes the MQTT connection.

p.disconnect()

Notes

  • Authentication tokens are valid for 7 days. The SDK will automatically reconnect and refresh the token when it expires.
  • Topic names must not contain /, +, #, or --.
  • Two clients cannot share the same postbox ID and secret at the same time within a project.

Tests

python tests\run_all.py

Metadata

Release files for cloudpostoffice 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudpostoffice 1.2.3
File Size Uploaded Provenance Actions
cloudpostoffice-1.2.3.tar.gz 12.6 kB Without provenance Details for cloudpostoffice-1.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cloudpostoffice 1.2.3
File Interpreter ABI Platform Actions
cloudpostoffice-1.2.3-py3-none-any.whl Python 3 none any Details for cloudpostoffice-1.2.3-py3-none-any.whl

Total release size: 23.0 kB

Release files / cloudpostoffice-1.2.3.tar.gz

Download URL cloudpostoffice-1.2.3.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1e040a56639b817b56bd909b57e9075fb5e8e5d2d361d5edfae91d3c9e52ec3a
BLAKE2b-256 checksum
How to use checksums
84f4df5741dcb5569ffaaafaf0320d1e6f721e21f66db2e137c4b5bf6b71c984
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / cloudpostoffice-1.2.3-py3-none-any.whl

Download URL cloudpostoffice-1.2.3-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab42ffac8893acb3826d0c80d7882ffcd7385c9186288a6c0c4c8ee2c16ff8d4
BLAKE2b-256 checksum
How to use checksums
2f9938e340312de13beaa1faab6a4c382c96bc55b1bfa2badae006438b47d761
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for cloudpostoffice 1.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page