Skip to main content

Twitch OAuth client with token management and authenticated HTTP requests

Project description

twitch-client

Twitch OAuth client with token management and authenticated HTTP requests for the Twitch Helix API.

Installation

pip install twitch-client

Usage

Environment Setup

Create a .env file or set environment variables:

TWITCH_CLIENT_ID=your_client_id
TWITCH_CLIENT_SECRET=your_client_secret
TWITCH_ACCESS_TOKEN=your_access_token
TWITCH_REFRESH_TOKEN=your_refresh_token

Basic Usage

import asyncio
from twitch_client import TwitchHTTPClient

async def main():
    async with TwitchHTTPClient() as client:
        # Get user info
        response = await client.get("/users", params={"login": "twitch"})
        print(response)

asyncio.run(main())

Manual Token Management

from twitch_client import TwitchAuth, TwitchCredentials

async def main():
    # Load credentials
    credentials = TwitchCredentials()

    # Create auth manager
    async with TwitchAuth(credentials) as auth:
        # Get valid token (refreshes automatically if needed)
        token = await auth.get_token()

        # Get token info including scopes
        info = await auth.get_token_info()
        print(f"Scopes: {info.scopes}")

asyncio.run(main())

Custom Credentials Location

import os
os.environ["TWITCH_ENV_FILE"] = "~/my-secrets/.env"

from twitch_client import TwitchHTTPClient
# Will load from custom .env location

Features

  • Automatic token refresh before expiration
  • Pydantic-based configuration validation
  • Async HTTP client with httpx
  • Rate limit handling
  • Comprehensive error types

API

TwitchHTTPClient

The main HTTP client for making authenticated requests:

  • get(endpoint, params) - GET request
  • post(endpoint, data, params) - POST request
  • patch(endpoint, data, params) - PATCH request
  • put(endpoint, data, params) - PUT request
  • delete(endpoint, params) - DELETE request

TwitchAuth

Token management:

  • get_token() - Get valid access token
  • refresh_token() - Force token refresh
  • get_token_info() - Get token metadata and scopes

Exceptions

  • TwitchClientError - Base exception
  • TwitchAuthError - Authentication errors
  • TwitchTokenRefreshError - Token refresh failed
  • TwitchAPIError - API request failed
  • TwitchRateLimitError - Rate limit exceeded

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

twitch_client-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

twitch_client-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitch_client-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.7 Darwin/25.2.0

File hashes

Hashes for twitch_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 51b7895b4dd9faf504d2fd07dfb4be4235083a7c5c484210eb73a18908cc6c2b
MD5 b69ddcf2732f9c973b4e4401c3fa4f70
BLAKE2b-256 44788d5405ef0628f88fda92f344be051153d8a17ea73d89f6a655a758caa3f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: twitch_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.13.7 Darwin/25.2.0

File hashes

Hashes for twitch_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1225304d931323c4d9ed08561ec7f290f81b68abfb18135a3a5efa7685a8fb2
MD5 58a74c2c7e54216c56ed5bfcd57b3641
BLAKE2b-256 2f2352ec30266a1c9be790bf4298938f727090ea754c3dcd50fa9b34cb88c113

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