Python API wrappers for PeerTube using openapi-python-client.
Project description
PeerTube Python API Client
Modern Python client library for the PeerTube API using openapi-python-client. Provides type-safe, well-structured clients with both synchronous and asynchronous support.
Overview
This package provides a comprehensive Python client for the PeerTube API, automatically generated from the official OpenAPI specification. It uses httpx for HTTP operations and attrs for type-safe data classes.
Installation
pip install peertube
Quick Start
Basic Client Usage
from peertube import Client
from peertube.api.video import get_categories, get_video
# Create an unauthenticated client for public endpoints
client = Client(base_url="https://your-peertube-instance.com")
# Get video categories
categories = get_categories.sync(client=client)
print(f"Available categories: {list(categories.keys())}")
# Get specific video details
video = get_video.sync(client=client, id="video-uuid")
print(f"Video: {video.name}")
Authenticated Client Usage
from peertube import AuthenticatedClient
from peertube.api.my_user import get_user
# Create authenticated client for protected endpoints
auth_client = AuthenticatedClient(
base_url="https://your-peertube-instance.com",
token="your-api-token"
)
# Get current user information
user = get_user.sync(client=auth_client)
print(f"Logged in as: {user.username}")
Asynchronous Usage
import asyncio
from peertube import Client
from peertube.api.video import get_categories, get_languages
async def get_video_metadata():
client = Client(base_url="https://your-peertube-instance.com")
async with client as async_client:
# Run multiple requests concurrently
categories, languages = await asyncio.gather(
get_categories.asyncio(client=async_client),
get_languages.asyncio(client=async_client)
)
return categories, languages
# Run async function
categories, languages = asyncio.run(get_video_metadata())
Advanced Configuration
from peertube import AuthenticatedClient
# Client with custom configuration
client = AuthenticatedClient(
base_url="https://your-peertube-instance.com",
token="your-api-token",
timeout=30.0,
verify_ssl=True, # Set to False only for testing
follow_redirects=True,
headers={"User-Agent": "MyPeerTubeApp/1.0"},
httpx_args={
"proxies": {"https://": "https://proxy.example.com"}
}
)
Response Handling
from peertube.api.video import get_video
# Simple response (just the data)
video = get_video.sync(client=client, id="video-uuid")
# Detailed response (includes status code, headers, etc.)
response = get_video.sync_detailed(client=client, id="video-uuid")
if response.status_code == 200:
video = response.parsed
print(f"Status: {response.status_code}")
print(f"Headers: {response.headers}")
else:
print(f"Error: {response.status_code}")
API Coverage
The client provides access to all PeerTube API endpoints organized by functionality:
Core API Modules
- video: Video management (get, delete, categories, languages, licenses)
- videos: Video listing and import operations
- accounts: Account and user information
- users: User management and administration
- session: Authentication and session management
- search: Video, channel, and playlist search
- my_user: Current user profile and settings
- video_channels: Video channel management
- video_playlists: Playlist operations
Additional Modules
- config: Instance configuration
- register: User registration
- my_subscriptions: Subscription management
- my_notifications: Notification handling
- video_comments: Comment operations
- live_videos: Live streaming
- stats: Instance statistics
Error Handling
from peertube.errors import UnexpectedStatus
from peertube.api.video import get_video
try:
video = get_video.sync(client=client, id="invalid-uuid")
except UnexpectedStatus as e:
print(f"API error: {e.status_code} - {e.content}")
Type Safety
The client provides full type annotations and IDE auto-completion:
from peertube.models import Video
from peertube.types import Response
# Type-safe response handling
response: Response[Video] = get_video.sync_detailed(client=client, id="uuid")
video: Video = response.parsed # Fully typed video object
Requirements
- Python 3.10+
- httpx >= 0.23.0
- attrs >= 22.2.0
Development
This package is automatically generated from the PeerTube OpenAPI specification using openapi-python-client.
Regenerating the Client
To update the client when the PeerTube API changes:
# Install development dependencies
pip install openapi-python-client
# Update the OpenAPI spec in assets/openapi.json
# Then regenerate the client
openapi-python-client generate --path assets/openapi.json --output-path src/peertube --meta none --overwrite
Testing
# Run all tests
pytest
# Run specific test files
pytest tests/test_client_generation.py -v
pytest tests/test_api_functions.py -v
Examples
See the examples/ directory for complete usage examples:
examples/client_usage.py- Basic client usage patterns- More examples coming soon...
Features
Generated Client Benefits
- Type Safety: Full type annotations with proper typing support
- Dual Clients:
Client(unauthenticated) andAuthenticatedClient(with token) - Async Support: Both sync and async methods for all endpoints
- httpx Based: Uses modern httpx library for HTTP requests
- Context Manager: Proper resource management with
withstatements - Customizable: Supports custom timeout, SSL settings, headers, cookies
API Endpoint Coverage
- ✅ Video Management: Get, list, upload, delete videos
- ✅ Video Metadata: Categories, languages, licenses
- ✅ Search: Videos, channels, playlists
- ✅ User Management: Registration, profiles, settings
- ✅ Authentication: Login, logout, token management
- ✅ Video Channels: Channel operations and management
- ✅ Playlists: Playlist creation and management
- ✅ Comments: Video comment operations
- ✅ Live Streaming: Live video operations
- ✅ Moderation: Content moderation tools
- ✅ Instance: Configuration and statistics
Contributing
This project follows modern Python development practices:
- Type hints for all functions
- Pydantic models for data validation
- Comprehensive error handling
- 100-character line length limit
- pytest for testing
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file peertube-1.1.1.tar.gz.
File metadata
- Download URL: peertube-1.1.1.tar.gz
- Upload date:
- Size: 583.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ce728b189c879964dfd7fbd305058a85092a0a8813f9488bd7ca14afc27b285
|
|
| MD5 |
9b6695709e8e9f607f22cfda030d17a6
|
|
| BLAKE2b-256 |
1d069ee0a76917b69daffdbe568b150d513d988fa2d15e335774d20688a9d5bc
|
File details
Details for the file peertube-1.1.1-py3-none-any.whl.
File metadata
- Download URL: peertube-1.1.1-py3-none-any.whl
- Upload date:
- Size: 839.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a93089e8522c26b5b02202197447c9ee10ac540787ca914f365f1c6c68ccdbcf
|
|
| MD5 |
27e8fb9381668afda9f42aa0fe8fcaf5
|
|
| BLAKE2b-256 |
49af763a7d15f5239f5b639f33afdb8613f99c63f4fd85fdb6d2fbc081a3195c
|