Skip to main content

Ampost Python SDK

The official Python client for the Ampost API: publish, schedule and track posts on Instagram, Facebook, Threads, X, YouTube, Pinterest, Bluesky, Telegram and Discord with one call.

  • Typed requests and responses (TypedDicts) for every endpoint, generated from the OpenAPI document
  • Sync and async clients on httpx
  • Retries on 429 and 5xx with Retry-After, automatic Idempotency-Keys, typed errors
  • Pagination by iteration and a one-call media upload
  • Python 3.9+

Install

pip install ampost

Quick start

Create an API key in Settings, API keys, connect Bluesky and Threads in the dashboard, then:

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"]])

Leave out publishNow for a draft, or set "scheduledFor": "2026-12-01T09:00:00Z" to schedule it (paid plans). Request bodies and responses are plain dicts with the API's field names; your editor and mypy check them against the typed models in ampost.models.

The async client has the same methods:

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())

Authentication

Every request sends the key as Authorization: Bearer <key>. Without api_key the client reads AMPOST_API_KEY, and AMPOST_BASE_URL overrides https://api.ampost.io.

client = Ampost(
    api_key="amp_...",
    max_retries=2,   # after a 429, a 5xx or a network error
    timeout=60.0,    # seconds per attempt
)

A key has scopes (posts:write, analytics:read, ...) and can be limited to some platform sets. A call outside them raises PermissionDeniedError with code INSUFFICIENT_SCOPE or PLATFORM_SET_NOT_ALLOWED. See scopes.

Use the client as a context manager (with Ampost() as client:) or call client.close(). To set proxies or transports, pass your own http_client=httpx.Client(...); you close that one yourself.

Errors

Every API error is {"error": {"code", "message", "details"}}, raised as a subclass of APIError:

from ampost import APIError, BadRequestError, RateLimitError

try:
    client.posts.create({"text": "x" * 500, "targets": [{"platforms": ["bluesky"]}]})
except BadRequestError as error:
    print(error.code, error.details)  # CONTENT_TOO_LONG, ...
except RateLimitError as error:
    print(f"retry in {error.retry_after} s")
except APIError as error:
    print(error.status, error.code, error.request_id)
Status Class Typical code
400 BadRequestError VALIDATION_FAILED, CONTENT_TOO_LONG, PLATFORM_NOT_CONNECTED
401 AuthenticationError UNAUTHORIZED
403 PermissionDeniedError INSUFFICIENT_SCOPE, UPGRADE_REQUIRED, PLATFORM_COMING_SOON
404 NotFoundError POST_NOT_FOUND, ACCOUNT_NOT_FOUND
409 ConflictError INVALID_STATUS_TRANSITION, IDEMPOTENCY_KEY_REUSED
413 PayloadTooLargeError PAYLOAD_TOO_LARGE
422 UnprocessableEntityError ANALYTICS_NOT_AVAILABLE_ON_PLATFORM
429 RateLimitError RATE_LIMITED, QUOTA_EXCEEDED
5xx InternalServerError INTERNAL_ERROR, PLATFORM_REQUEST_FAILED

No response at all is APIConnectionError (APITimeoutError after timeout). All of them extend AmpostError. Quote error.request_id when you contact support. Every code is listed in the docs.

A post that was accepted can still fail on one platform: check post["platformPosts"][i]["status"] and ["error"], or subscribe to webhooks.

Idempotency

posts.create, posts.publish, posts.retry, posts.import_csv, accounts.connect, platform_sets.create, webhooks.create and feedback.submit take an Idempotency-Key. The SDK sends a new key with each call and keeps it across that call's retries, so a retried request never posts twice. To stay safe across restarts too (a cron job, a queue worker), pass your own key:

client.posts.create(
    {"text": "v1.4.0 is out", "targets": [{"platforms": ["bluesky"]}], "publishNow": True},
    idempotency_key="release-v1.4.0",
)

The same key with the same request returns the first result for 24 hours; with a different request it is ConflictError IDEMPOTENCY_KEY_REUSED. See idempotency.

Retries

What happened Retried?
429 RATE_LIMITED, QUOTA_EXCEEDED Yes, after Retry-After, if it is under max_retry_delay (60 s)
409 IDEMPOTENCY_REQUEST_IN_PROGRESS Yes
5xx, timeout, network error Reads and calls with an Idempotency-Key only
Anything else No

Waits without Retry-After back off from 0.5 s to 8 s. Set max_retries on the client or per call: client.posts.get(post_id, max_retries=0). Every method also takes timeout and extra_headers.

Pagination

List methods return the first page. Iterate it to get every item, page after page:

page = client.posts.list(status="failed", limit=50)
print(page.data, page.total, page.has_next_page())

for post in client.posts.list(status="failed"):
    client.posts.retry(post["id"])

With AsyncAmpost, await the call for one page or async for over it for every item:

page = await client.posts.list(limit=50)
async for account in client.accounts.list():
    print(account["platform"])
accounts = await client.accounts.list().to_list()

Query parameters are keyword arguments in snake_case: platform_set_id=, and from_= for from.

Media upload

media.upload() takes a path or bytes, sends the file straight to storage (your API key is not sent there), waits until Ampost has checked it and returns a media item:

video = client.media.upload("launch.mp4")
client.posts.create({
    "text": "We launched 🚀",
    "media": [video],
    "targets": [{"platforms": ["youtube", "threads"]}],
    "options": {"youtube": {"title": "Launch day"}},
})

Public URLs work without an upload: "media": [{"url": "https://example.com/a.jpg", "type": "image"}]. For files on a user's device, show uploadPageUrl from media.create_upload() and call media.wait_for_upload(upload_id). See media upload.

Everything else

Each tag of the API is an attribute: posts, accounts, platform_sets (and posting queues), media, analytics, webhooks, platforms, docs, feedback. The types of every request and response are in ampost.models:

from ampost import models

def caption(post: models.Post) -> str:
    return post["text"]

client.platforms.list() returns each platform's limits and options, and client.posts.validate(body) checks a post without creating it.

AI agents can use the same API through the hosted MCP server at https://api.ampost.io/mcp (setup).

Development

The code in src/ampost/_generated/ comes from openapi.json; never edit it by hand. With uv:

uv sync
uv run python scripts/generate.py                                              # from the committed openapi.json
uv run python scripts/generate.py --spec https://api.ampost.io/openapi.json    # refresh the snapshot, then generate
uv run pytest && uv run mypy
AMPOST_API_KEY=amp_... uv run pytest tests/test_smoke.py                       # reads and validates only

Why this generator: openapi-python-client and OpenAPI Generator emit a model class per schema and a module per operation, with their own serialization layer; the result is large and reads unlike the API docs. scripts/generate.py uses only the standard library and turns the spec into TypedDicts (so requests and responses stay the plain JSON dicts the docs show) and one method per operation. The hand-written client (_client.py) adds auth, retries, idempotency, errors and pagination on httpx, the only runtime dependency besides typing_extensions.

License

MIT

Metadata

Release files for ampost 0.1.0

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

Source distribution (sdist)

Source distribution for ampost 0.1.0
File Size Uploaded Provenance Actions
ampost-0.1.0.tar.gz 52.4 kB With provenance Details for ampost-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 109.5 kB

Release files / ampost-0.1.0.tar.gz

Download URL ampost-0.1.0.tar.gz
Size 52.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e29bffc2494b892d608ab51552d895c6b634ece973053e619876fcb5b854966e
BLAKE2b-256 checksum
How to use checksums
b801863941ca782d43955d5b5dcc2579a64d824bba5d9f03ee3f43c7dfe423e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / ampost-0.1.0-py3-none-any.whl

Download URL ampost-0.1.0-py3-none-any.whl
Size 57.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f431f8af3d53657b105a7e6756ee34f18182b60b5ecf14555eb870ee23c8da4
BLAKE2b-256 checksum
How to use checksums
47617aaee2bdfba3f3e3012f7d9b158dbc148a695069b5f6182bc3093a1152e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for ampost 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ampost-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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