Python SDK for SRG+
Project description
SRG+ Python SDK
Python client for the SRG+ API — manage hub profiles, channels, contents, assets, workspaces, and permissions.
Installation
pip install srgplus
Requires Python 3.11+ and depends on httpx and pydantic.
Quick start
from srg import SRGClient
with SRGClient(api_key="srgplus_...") as client:
profiles = client.hub_profiles.list()
contents = client.contents.filter(profiles[0].id)
The api_key can also be provided via the SRG_API_KEY environment variable:
export SRG_API_KEY=srgplus_...
client = SRGClient() # reads from env
Async
import asyncio
from srg import AsyncSRGClient
async def main():
async with AsyncSRGClient(api_key="srgplus_...") as client:
channels = await client.channels.list(hub_profile_id="hp-id")
# workspace_id is fetched lazily on first access:
ws_id = await client.get_workspace_id()
asyncio.run(main())
Per-request API keys (multi-tenant servers)
A single SRGClient / AsyncSRGClient can serve any number of workspaces from
one shared httpx connection pool. Bind the key per call instead of per
client:
from srg import SRGClient
client = SRGClient() # no eager bootstrap, no default key
# Option A — scoped clone (returns a thin wrapper that reuses the pool)
scoped = client.with_api_key("srgplus_workspace_a")
scoped.hub_profiles.list()
# Option C — context manager
with client.use_api_key("srgplus_workspace_b"):
client.hub_profiles.list()
The same patterns work on AsyncSRGClient:
async with AsyncSRGClient() as client:
async with client.use_api_key("srgplus_workspace_a"):
await client.hub_profiles.list()
scoped = client.with_api_key("srgplus_workspace_b")
await scoped.hub_profiles.list()
Implementation detail: an internal contextvars.ContextVar carries the active
key through the call stack, so with_api_key / use_api_key are safe under
asyncio and threaded servers. Each request adds its own Authorization
header — the underlying httpx.Client is shared.
When you call SRGClient(api_key=...) the eager way, that key is used as the
default for every request that doesn't have one bound — so existing single-key
code continues to work unchanged.
Configuration
| Parameter | Env var | Default |
|---|---|---|
api_key |
SRG_API_KEY |
required |
timeout |
— | 30.0 s |
Documentation
Full API reference and usage examples are in docs/:
| Section | Reference |
|---|---|
Client (SRGClient, AsyncSRGClient) |
docs/client.md |
| Users | docs/resources/users.md |
| Invitations | docs/resources/invitations.md |
| Permissions | docs/resources/permissions.md |
| Permission Groups | docs/resources/permission_groups.md |
| Hub Profiles | docs/resources/hub_profiles.md |
| Workspaces | docs/resources/workspaces.md |
| Assets | docs/resources/assets.md |
| Channels | docs/resources/channels.md |
| Contents | docs/resources/contents.md |
| Error handling | docs/exceptions.md |
License
MIT — see LICENSE.
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
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 srgplus-0.2.0.tar.gz.
File metadata
- Download URL: srgplus-0.2.0.tar.gz
- Upload date:
- Size: 93.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f41f2e0afa4c17d216ce20a3546e041075b7f0c6d2498d59ee84469e43c5e8f2
|
|
| MD5 |
8108ec7f86407833b4578f86e668cf2a
|
|
| BLAKE2b-256 |
3e0f228121ee8f476e34a064716f1c500cd785c1e837b817f00a2babadc2a387
|
File details
Details for the file srgplus-0.2.0-py3-none-any.whl.
File metadata
- Download URL: srgplus-0.2.0-py3-none-any.whl
- Upload date:
- Size: 61.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7d307b520a04a2dc94b08cec7cc84891b43adacd6c4ffd8fad2c2db326da9a1
|
|
| MD5 |
241d16c194845e51910bd58b6957cb1d
|
|
| BLAKE2b-256 |
f38cc72e2044860de4b8a379119d730f66256c3f91323ae4d091b0e5c1c76aed
|