Firmreader Docs Online logo

Python

Scopri come installare e usare l’SDK Python di Firmreader per creare post, elencare contenuti dei canali e gestire errori API da Python 3.9 in poi.

L’SDK Python supporta Python 3.9 e versioni successive e offre un client sincrono. Un client asincrono è disponibile in firmreader.aio.

Installazione

pip install firmreader

Inizializzare il client

import os
from firmreader import Firmreader

client = Firmreader(api_key=os.environ["FIRMREADER_API_KEY"])  # fr_live_...

Creare un 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}")

Elencare i post

posts = client.posts.list(channel_id="ch_company_news", limit=20)

for post in posts.data:
    print(post.title)

Gestire gli errori

Le risposte non 2xx generano FirmreaderError, che contiene lo status HTTP e un code API.

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

Passa idempotency_key="..." a qualsiasi metodo di scrittura per evitare che i tentativi ripetuti creino post duplicati.

Last updated on