SDKs & Libraries
Python SDK
Integrate PinBridge in Python backends, workers, and automation pipelines.
Overview
Use the official pinbridge-sdk package to implement auth, board discovery, publishing, and scheduling with typed models.
What You Will Learn
- Initialize sync and async clients for scripts, workers, and services.
- Use typed request/response models for safer integration changes.
- Switch between bearer token and API key auth in the same runtime workflow.
Implementation Checklist
- Install pinbridge-sdk and centralize client initialization (base URL, timeout, headers).
- Authenticate once, then persist API key or bearer token in your runtime.
- Wrap publish and schedule calls with idempotency keys and structured logging.
Important Resources
Official package and source links for direct installation and version tracking.
Deep Dive
1) Sync vs Async client usage
Use the sync client for scripts, cron jobs, and low-concurrency workers. Use the async client in high-throughput services where network calls should run concurrently.
- Sync client is simpler for one-shot publish flows.
- Async client improves throughput for account, board, and status fan-out calls.
- Keep one initialized client per process/request scope instead of recreating per call.
2) Typed models as contract protection
Use SDK request models for every write operation so invalid fields are caught before requests hit production.
- Prefer `PinCreate` and schedule models over raw dict payloads.
- Update model usage with SDK version upgrades to track API contract changes.
- Pair typed models with unit tests for serialization-critical workflows.
3) Token and API key strategy in one runtime
Use bearer auth during interactive user flows and API keys for backend automation, then standardize this at service boundaries.
- Set bearer token after login for user-scoped operations.
- Use API keys for non-interactive workers and long-lived integrations.
- Never mix auth context silently; log active auth mode in structured logs.
Example
pip install pinbridge-sdk
from pinbridge_sdk import PinbridgeClient
from pinbridge_sdk.models import LoginRequest, PinCreate
with PinbridgeClient(base_url="https://api.pinbridge.io") as client:
auth = client.auth.login(LoginRequest(email="you@example.com", password="super-secret"))
client.set_bearer_token(auth.access_token)
accounts = client.pinterest.list_accounts()
boards = client.pinterest.list_boards(accounts[0].id)
asset = client.assets.upload_video("./pin-video.mp4", content_type="video/mp4")
pin = client.pins.create(
PinCreate(
account_id=accounts[0].id,
board_id=boards[0].id,
title="SDK workflow pin",
asset_id=asset.id,
idempotency_key="sdk-workflow-pin-001",
)
)
print(pin.id, pin.status)