Ampost Python SDK

By Published Updated

ampost is the official Python client for the Ampost API: one call publishes, schedules or drafts a post on every network you connect, with a sync and an async client on httpx.

The package is coming to PyPI as ampost, soon. Until then, install it from GitHub with the command below; the code is the same.

Install

Python 3.9 or later. It depends only on httpx and typing_extensions.

terminal
pip install git+https://github.com/ampost-io/ampost-python

Publish a post

Create an API key in Settings, API keys, connect Bluesky and Threads in the dashboard, and put the key in AMPOST_API_KEY. Then:

post.py
import os
from ampost import Ampost

client = Ampost(api_key=os.environ["AMPOST_API_KEY"])

post = client.posts.create({
    "text": "Hello from the Ampost API 👋",
    "targets": [{"platforms": ["bluesky", "threads"]}],
    "publishNow": True,
})
print(post["id"], post["status"], [(p["platform"], p["status"]) for p in post["platformPosts"]])

What it does

  • Typed requests and responses (TypedDicts in ampost.models) for every endpoint, generated from the OpenAPI document.
  • Ampost and AsyncAmpost with the same methods.
  • Retries on 429 and 5xx with Retry-After, an automatic Idempotency-Key per call, and typed errors (BadRequestError, RateLimitError, ...).
  • Pagination by iteration and a one-call media upload (client.media.upload("launch.mp4")).

Async

The async client reads AMPOST_API_KEY when you don't pass a key:

post_async.py
import asyncio
from ampost import AsyncAmpost

async def main() -> None:
    async with AsyncAmpost() as client:
        post = await client.posts.create({"text": "Hello", "targets": [{"platforms": ["bluesky"]}]})
        print(post["id"])

asyncio.run(main())