Skip to main content

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

srgplus-0.2.2.tar.gz (108.5 kB view details)

Uploaded Source

Built Distribution

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

srgplus-0.2.2-py3-none-any.whl (72.5 kB view details)

Uploaded Python 3

File details

Details for the file srgplus-0.2.2.tar.gz.

File metadata

  • Download URL: srgplus-0.2.2.tar.gz
  • Upload date:
  • Size: 108.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for srgplus-0.2.2.tar.gz
Algorithm Hash digest
SHA256 715e7ef9df71775b696326820fb9df9a37fa2c15c5b4c714c7c3667d16e7b256
MD5 fad19806f2726ed1b38cd66ba3691032
BLAKE2b-256 bd3d9346f168584473d3e3524e55bbcd3c9014a4f232c1fedbef0d5b1121c441

See more details on using hashes here.

File details

Details for the file srgplus-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: srgplus-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 72.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for srgplus-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3a8c42e9af742f2ca1b005b3aa663f6027f744c9e5bc8007eecd1e4142646a1
MD5 62bee5cee35a1c5fd16d1265eb1c238b
BLAKE2b-256 6141da6e6ead70e4886817b585c3b7acf3b6efeec594699fad31c2cab1c17cc8

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