Ampost Python SDK
By ArturPublished 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-pythonPublish 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 inampost.models) for every endpoint, generated from the OpenAPI document. AmpostandAsyncAmpostwith the same methods.- Retries on 429 and 5xx with
Retry-After, an automaticIdempotency-Keyper 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())Links
- Source code (MIT): github.com/ampost-io/ampost-python
- Guide: Post to social media from Python with Ampost
- REST API reference