Python
Learn how to install and use the Firmreader Python SDK to create posts, list channel content, and handle API errors in Python 3.9 and above.
The Python SDK targets Python 3.9+ and exposes a synchronous client. An async client is available under firmreader.aio.
Install
pip install firmreader
Initialize the client
import os
from firmreader import Firmreader
client = Firmreader(api_key=os.environ["FIRMREADER_API_KEY"]) # fr_live_...
Create a post
post = client.posts.create(
channel_id="ch_company_news",
title="Welcome to Firmreader",
body="We're excited to announce our new internal communications platform.",
priority="normal",
)
print(f"Published post {post.id}")
List posts
posts = client.posts.list(channel_id="ch_company_news", limit=20)
for post in posts.data:
print(post.title)
Handle errors
Non-2xx responses raise FirmreaderError, which carries the HTTP status and an API code.
from firmreader import FirmreaderError
try:
client.posts.create(channel_id="ch_invalid", title="Hi", body="...")
except FirmreaderError as err:
print(f"{err.status}: {err.code}")
Pass idempotency_key="..." to any write method so retried requests don't create duplicate posts.
Last updated on
