Skip to main content

Official Python SDK for Stophy - YouTube context API for AI agents.

Project description

stophy

Official Python SDK for Stophy YouTube context API for AI agents. Search videos, fetch transcripts, read comments and live chat, inspect channels and playlists, and get autocomplete suggestions, all returned as structured JSON.

Install

uv install stophy

Get an API key from your Stophy dashboard. The SDK sends it as Authorization: Bearer <key> on every request.

Quick start

import os
from stophy import Stophy

stophy = Stophy(os.environ["STOPHY_API_KEY"])

result = stophy.video(type="transcript", video_url="https://www.youtube.com/watch?v=D7liwdjvhWc")
print(result["data"]["text"])

Methods

Method Description
stophy.video(...) Details, transcript, comments, replies, or live chat (set type)
stophy.search(...) Search with filters for type, sort, date, duration, features
stophy.channel(...) Channel metadata + content by tab
stophy.playlist(...) Playlist items, paginated
stophy.suggest(...) Search autocomplete suggestions
stophy.credits() Current credit balance
stophy.logs(...) Recent request logs
stophy.usage(...) Daily credit/request counts

Arguments are keyword-only and snake_case; the SDK maps them to the API's field names for you. video() is overloaded on type, so the returned data is typed for the variant you asked for (transcript, comments, details, …).

# Search
results = stophy.search(q="typescript tutorial", sort_by="popularity", duration="long")

# Comments, then replies to a comment
comments = stophy.video(type="comments", video_url=url, sort_by="top")
token = comments["data"]["items"][0].get("repliesToken")
if token:
    replies = stophy.video(type="replies", continuation_token=token)

# Autocomplete and account
print(stophy.suggest(q="react")["data"]["suggestions"])
print(stophy.credits()["data"]["credits"])

Pagination

token = None
while True:
    page = stophy.search(q="lofi", continuation_token=token)
    ...  # handle page["data"]["items"]
    token = page["data"].get("continuationToken")
    if not token:
        break

Errors

Non-2xx responses raise StophyError:

from stophy import Stophy, StophyError

try:
    stophy.credits()
except StophyError as err:
    print(err.status, err.code, err, err.request_id)
    # err.code: "UNAUTHORIZED" | "INSUFFICIENT_CREDITS" | "BAD_REQUEST" |
    #           "INVALID_INPUT" | "NOT_FOUND" | "CONCURRENCY_LIMITED" | "INTERNAL_ERROR"

License

MIT

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

stophy-0.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

stophy-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file stophy-0.1.0.tar.gz.

File metadata

  • Download URL: stophy-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for stophy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bef7be8b8d29ac4ae3629ef78d3592494de2489418a88a2789fe8d07637f331c
MD5 228632c425aafbad3b0e63fd8d889364
BLAKE2b-256 7cd49b3b822259c2c629b14d6f8bacbffeb8aff20374bba3696aa3159485ed4d

See more details on using hashes here.

File details

Details for the file stophy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: stophy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for stophy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 695b8df85e7a584edc6726b15c9e7013e2b3ca61e5f1f9cb169ff35aa2d79c2c
MD5 7dd2737df0107b8c77ec382412a48f27
BLAKE2b-256 ee7676c197adf86a410b1aafade10b9c6ddb2145760bd1b482ed753248a7e99d

See more details on using hashes here.

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