An asynchronous Python client for interacting with the HeyGen Streaming API, designed for high-performance and reliability.
- Full async/await support
- Type hints throughout
- Pydantic models for request/response validation
- Environment-based configuration
- Singleton client instance
- Built-in error handling
# Using pip pip install heygen-streaming-sdk # Using poetry poetry add heygen-streaming-sdk
Configuration is handled through environment variables. Create a .env file in your project root:
HEYGEN_API_KEY=your_api_key_here HEYGEN_BASE_URL=https://api.heygen.com/v1 HEYGEN_TIMEOUT=30
Or set them in your environment:
export HEYGEN_API_KEY=your_api_key_here export HEYGEN_BASE_URL=https://api.heygen.com/v1 export HEYGEN_TIMEOUT=30
from heygen_streaming import client async def create_streaming_session(): # The client is a singleton, so you can import and use it directly session = await client.create_session( # Your session configuration here ) return session
from fastapi import FastAPI, Depends from heygen_streaming import client, config app = FastAPI() @app.get("/create-session") async def create_session(): """Create a new streaming session.""" try: session = await client.create_session( # Your session configuration here ) return {"session_id": session.id} except Exception as e: return {"error": str(e)}, 500
The main client class for interacting with the HeyGen Streaming API.
create_session(request: NewSessionRequest) -> NewSessionResponse: Create a new streaming session.start(): Initialize the HTTP client.close(): Close the HTTP client.
Configuration is available through the config object:
from heygen_streaming.config import config print(f"Using API base URL: {config.BASE_URL}")
The SDK provides the following exceptions:
HeyGenAPIError: Base exception for all API errorsAuthenticationError: Raised for authentication failuresValidationError: Raised for request/response validation failures
- Clone the repository
- Install dependencies:
poetry install
- Create a
.envfile based on.env.example
Run the test suite:
pytest tests/
ruff check .black .MIT