Skip to main content

SocialAPI: public social media data in one schema

PyPI version License

Official Python SDK for the SocialAPI: profiles, posts, comments, transcripts,
searches and trends from TikTok, Instagram, Threads and Facebook, in one schema. See the docs for every endpoint.

Python 3.10+. Typed with Pydantic.

Installation

pip install socialapihq

Usage

Each platform is an attribute of the client and each endpoint a method on it. Create an API key in the dashboard; it is sent as Authorization: Bearer sapi_…, and every account starts with 100 free credits.

import os

from socialapihq import SocialAPI

client = SocialAPI(api_key=os.environ["SOCIALAPI_API_KEY"])

profile = client.tiktok.profile(handle="nike").data
print(profile.display_name, profile.followers)  # Nike 9440793

for post in client.instagram.profile_posts(handle="natgeo").data:
    print(post.url, post.stats.likes)

Methods take the endpoint's parameters as keyword arguments in snake case (secUid is sec_uid) and return typed models: .data for one item, .data and .pagination for a list. Every platform answers with the same field names, and what only one platform has sits under ext. api_key defaults to the SOCIALAPI_API_KEY environment variable.

Models are Pydantic: .model_dump() gives a dict, .to_json() the JSON.

Pagination

A list answers pagination.next_cursor while pagination.has_more is true. Pass it back as cursor for the next page:

cursor = None
while True:
    page = client.tiktok.profile_posts(handle="nike", cursor=cursor)
    for post in page.data:
        print(post.id, post.stats.views)
    if not page.pagination.has_more:
        break
    cursor = page.pagination.next_cursor

Each page costs credits like any call. A cached answer is free.

Transcripts

transcript = client.tiktok.post_transcript(
    url="https://www.tiktok.com/@nike/video/7711414040114892045",
).data

print(transcript.language, transcript.text)
for cue in transcript.cues:
    print(cue.start_seconds, cue.text)  # 0.02 Pole or podium?

A transcript costs 5 credits and is cached for 30 days.

Error handling

A refused call raises a SocialAPIError. Its code is stable to build logic on, and refused calls cost no credits:

from socialapihq import SocialAPIError

try:
    client.instagram.profile(handle="no-such-account")
except SocialAPIError as error:
    print(error.status, error.code, error.message, error.request_id)
    # 404 NOT_FOUND No Instagram account matches this handle. req_…

RATE_LIMITED errors carry retry_after in seconds. See Errors for every code.

Configuration

client = SocialAPI(
    api_key="sapi_…",
    base_url="https://api.socialapi.sh",  # the default
    timeout=30,  # seconds to wait for each answer
)

with SocialAPI() as client:  # closes its connections at the end
    print(client.account.get_credits().balance)

The generated classes (TikTokApi, InstagramApi…) are exported too. Their …_with_http_info methods give the status and headers, such as X-Credits-Charged.

API reference

Facebook

Method Description
facebook.event() One event
facebook.events() A city's upcoming events
facebook.events_search() Events matching a query
facebook.marketplace_item() One Marketplace listing
facebook.marketplace_search() Marketplace listings for a query near a point
facebook.post() One post
facebook.post_comment_replies() The replies to one comment
facebook.post_comments() A post's comments
facebook.post_transcript() A video's captions as text with their times
facebook.profile() A Page or a public person
facebook.profile_photos() A Page's or person's photos
facebook.profile_posts() A Page's or person's posts
facebook.profile_videos() A Page's videos with their plays

Instagram

Method Description
instagram.highlight() A story highlight's stories
instagram.location() A place
instagram.location_posts() A place's top posts with their likes and comments
instagram.post() One post or reel with its counts
instagram.post_comments() A post's comments with their likes
instagram.profile() A profile with its follower and following counts
instagram.profile_highlights() An account's story highlights
instagram.profile_posts() An account's posts
instagram.profile_reels() An account's reels with their plays
instagram.profile_similar() Accounts like this one
instagram.search() Popular posts for a word or hashtag
instagram.sound() A sound
instagram.sound_posts() The reels that use a sound
instagram.trending() The reels feed Instagram gives a visitor
instagram.trending_topics() The explore page's trending keywords and accounts

Threads

Method Description
threads.post() One thread with its counts
threads.post_comments() A thread's replies
threads.profile() A profile with its follower count
threads.profile_media() An account's threads with photos or videos
threads.profile_posts() An account's threads
threads.profile_replies() An account's replies to other threads
threads.profile_reposts() Other people's threads an account reposted
threads.search() Threads matching a query
threads.search_users() Accounts matching a name
threads.trending() The feed Threads gives a visitor now

TikTok

Method Description
tiktok.collection_posts() The posts of a public saved collection
tiktok.hashtag() A hashtag with its post and view counts
tiktok.hashtag_posts() Posts under a hashtag
tiktok.live() Whether an account is live
tiktok.playlist_posts() The posts of a playlist
tiktok.post() One post with its counts
tiktok.post_comment_replies() The replies to one comment
tiktok.post_comments() A post's top-level comments
tiktok.post_related() Posts TikTok recommends beside one post
tiktok.post_transcript() A post's captions as text with their times
tiktok.profile() A profile with its exact follower and like counts
tiktok.profile_followers() An account's followers
tiktok.profile_following() The accounts an account follows
tiktok.profile_liked() Posts an account liked
tiktok.profile_playlists() The playlists an account made
tiktok.profile_posts() An account's posts
tiktok.profile_reposts() Other people's posts an account reposted
tiktok.search() Posts matching a query
tiktok.search_users() Accounts matching a query
tiktok.sound() A sound
tiktok.sound_posts() Posts that use a sound
tiktok.trending() What the explore page shows now

Account

Method Description
account.get_credits() The credits left in your workspace

Query parameters are keyword arguments of the method, such as handle="nike", cursor=cursor. Every endpoint, with its parameters and a real answer, is in the API Reference.

License

Apache-2.0

Metadata

Release files for socialapihq 0.1.3

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

Source distribution (sdist)

Source distribution for socialapihq 0.1.3
File Size Uploaded Provenance Actions
socialapihq-0.1.3.tar.gz 88.0 kB With provenance Details for socialapihq-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 299.4 kB

Release files / socialapihq-0.1.3.tar.gz

Download URL socialapihq-0.1.3.tar.gz
Size 88.0 kB
Tags Source
SHA-256 checksum
How to use checksums
12d9e46de97b741e249d2d85477ae074afe3a73e9d383fc7db2953b427d1ab71
BLAKE2b-256 checksum
How to use checksums
872b18eb945d3a6a33b2593ed10083750825cfb17a4e1c47d0a162b4c4493db0
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 25, 2026.

Transparency log

Release files / socialapihq-0.1.3-py3-none-any.whl

Download URL socialapihq-0.1.3-py3-none-any.whl
Size 211.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d99048d46757fffccf9676d6403f5da941e0d28c5a9a8a34760f22939a74f5ef
BLAKE2b-256 checksum
How to use checksums
31f0e7501ef5c4ac7fc38c50eed59277fcff65ceb15a9cf0a8498d065e333b09
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 25, 2026.

Transparency log

Security for socialapihq 0.1.3

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 socialapihq-0.1.3.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 25, 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.

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