Skip to main content

Official Python SDK for SocialAPI -- unified social media inbox API

Project description

SocialAPI Python SDK

PyPI version Python versions CI License: MIT

The official Python SDK for SocialAPI -- a unified social media inbox API that reads and responds to comments, DMs, reviews, and mentions across Instagram, Facebook, Google Reviews, TikTok, YouTube, X/Twitter, Trustpilot, and LinkedIn through a single REST API.

Installation

pip install socialapi

Requires Python 3.10 or later.

Quick Start

Synchronous

from socialapi import SocialAPI

client = SocialAPI(api_key="sapi_key_...")

# List connected accounts
accounts = client.accounts.list()
for account in accounts.data:
    print(f"{account.platform}: {account.name}")

# List comments on a post
comments = client.comments.list("acc_123", "post_456")
for comment in comments.data:
    print(comment.content.text)

# Reply to a comment
reply = client.interactions.reply("acc_123", "sapi_cmt_abc", text="Thanks!")

Asynchronous

import asyncio
from socialapi import AsyncSocialAPI

async def main():
    async with AsyncSocialAPI(api_key="sapi_key_...") as client:
        accounts = await client.accounts.list()
        for account in accounts.data:
            print(f"{account.platform}: {account.name}")

asyncio.run(main())

Authentication

Pass your API key directly or set the SOCIALAPI_API_KEY environment variable:

# Explicit
client = SocialAPI(api_key="sapi_key_...")

# From environment variable
import os
os.environ["SOCIALAPI_API_KEY"] = "sapi_key_..."
client = SocialAPI()

API keys are created in the SocialAPI dashboard or via the API. The full key is shown once at creation -- store it securely.

Usage Examples

Managing Accounts

# Connect a new account via OAuth
result = client.accounts.connect("instagram", metadata={"redirect_uri": "https://..."})

# Disconnect an account
client.accounts.disconnect("acc_123")

Publishing Posts

# Create a post across multiple accounts
post = client.posts.create(
    account_ids=["acc_123", "acc_456"],
    text="Hello from SocialAPI!",
)

# Schedule a post
post = client.posts.create(
    account_ids=["acc_123"],
    text="Scheduled post",
    scheduled_at="2026-04-01T12:00:00Z",
)

Direct Messages

# List DM threads
dms = client.dms.list("acc_123")

# Send a DM
client.dms.send("acc_123", thread_id="thread_789", text="Hello!")

Media Upload

# Upload media for use in posts
upload_info = client.media.upload_url(media_type="image", filename="photo.jpg")
# Upload to the presigned URL, then verify:
client.media.verify(media_id=upload_info.id)

Error Handling

The SDK raises typed exceptions for all API errors:

from socialapi import (
    SocialAPIError,
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    PlanLimitError,
    PlatformRateLimitError,
    ValidationError,
    NotSupportedError,
)

try:
    client.comments.list("acc_123", "post_456")
except NotFoundError as e:
    print(f"Not found: {e.message} (code: {e.code})")
except PlanLimitError:
    print("Monthly limit exceeded -- upgrade your plan")
except PlatformRateLimitError:
    print("Platform rate limit hit -- will auto-retry")
except AuthenticationError:
    print("Invalid API key")
except SocialAPIError as e:
    print(f"API error {e.status_code}: {e.message}")

Pagination

Single Page

response = client.comments.list("acc_123", "post_456", limit=10)
print(response.data)   # list of comments
print(response.count)  # total count

Auto-Pagination

# Synchronous -- iterates through all pages automatically
for comment in client.comments.list_auto("acc_123", "post_456"):
    print(comment.content.text)

# Asynchronous
async for comment in async_client.comments.list_auto("acc_123", "post_456"):
    print(comment.content.text)

Configuration

client = SocialAPI(
    api_key="sapi_key_...",
    base_url="https://api.social-api.ai",  # default
    timeout=30.0,                           # seconds, default
    max_retries=3,                          # default
)

Context Manager

Both clients support context managers for proper resource cleanup:

with SocialAPI(api_key="sapi_key_...") as client:
    accounts = client.accounts.list()

async with AsyncSocialAPI(api_key="sapi_key_...") as client:
    accounts = await client.accounts.list()

Custom HTTP Client

For advanced use cases, inject your own httpx client:

import httpx

http_client = httpx.Client(verify=False)  # custom SSL settings, proxies, etc.
client = SocialAPI(api_key="sapi_key_...", http_client=http_client)

API Reference

For full endpoint documentation, visit docs.social-api.ai.

Resources

Resource Description
client.accounts Manage connected social accounts
client.posts Create, update, delete, and retry posts
client.comments List and moderate comments
client.interactions Reply to comments, reviews, and mentions
client.dms List and send direct messages
client.reviews List reviews
client.mentions List mentions
client.media Upload and manage media files
client.usage Check usage statistics
client.keys Manage API keys
client.users Manage user profile
client.webhooks Configure webhook endpoints
client.billing Manage billing and subscriptions
client.oauth OAuth token exchange
client.search Search across accounts

Contributing

See CONTRIBUTING.md for development setup, testing, and PR guidelines.

License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

socialapi-0.1.1.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

socialapi-0.1.1-py3-none-any.whl (37.1 kB view details)

Uploaded Python 3

File details

Details for the file socialapi-0.1.1.tar.gz.

File metadata

  • Download URL: socialapi-0.1.1.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for socialapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4a704f958f409ade201774ae34009620a44bbabc8e1eec463a88d63038e1d024
MD5 58770b0974d0be61188f1bd4cfb3533e
BLAKE2b-256 d1803c906df89322d1711613a7957529f9bb0ef00a5baf643bb1ddd8534ff2c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for socialapi-0.1.1.tar.gz:

Publisher: publish.yml on SocialAPI-AI/socialapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file socialapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: socialapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for socialapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73146874b8503ea6ef5b8963ef99bf545ad16a669577c928d9ee2d2bb214c995
MD5 ab071105225502933cf8a9a166ecf2eb
BLAKE2b-256 71ad41d273f62965d1523b14d12d1309efb4e97e654f8f80f6195096718453a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for socialapi-0.1.1-py3-none-any.whl:

Publisher: publish.yml on SocialAPI-AI/socialapi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page