Skip to main content

Customer-facing Python SDK and `usvc` CLI for UnitySVC

Project description

unitysvc-py

Customer-facing Python SDK and usvc CLI for UnitySVC.

This package is a thin, typed facade over the UnitySVC customer API. It exposes:

  • A sync Client and async AsyncClient for the customer-tagged backend endpoints.
  • The usvc CLI for managing the same resources from the terminal.

Status: early scaffolding. The customer API currently exposes only a handful of endpoints (aliases, recurrent requests, secrets); the SDK tracks those today and will grow as the backend adds more.

Install

pip install unitysvc-py

Programmatic usage

from unitysvc_py import Client

client = Client(api_key="svcpass_...")  # or Client.from_env()

# List and set secrets
secrets = client.secrets.list()
for s in secrets.data:
    print(s.name, s.id)

client.secrets.create({"name": "openai-key", "value": "sk-..."})

Configuration

The SDK is configured via a small set of environment variables. Only UNITYSVC_API_KEY is required; everything else has a sensible default.

Variable Purpose Default
UNITYSVC_API_KEY Customer API key (svcpass_...) (required)
UNITYSVC_API_URL Control-plane API base URL https://api.staging.unitysvc.com/v1
UNITYSVC_API_BASE_URL HTTP API gateway base URL (inference) (unset)
UNITYSVC_S3_BASE_URL S3-compatible gateway base URL (unset)
UNITYSVC_SMTP_BASE_URL SMTP gateway base URL (unset)

The customer context is encoded entirely in the API key, so no separate customer_id argument is required.

UNITYSVC_API_URL is what the SDK itself uses for control-plane calls. The *_BASE_URL variables are exposed on Client as client.api_base_url, client.s3_base_url, client.smtp_base_url for downstream inference/storage/email SDKs to pick up — the SDK itself doesn't talk to them directly.

Async client

import asyncio
from unitysvc_py import AsyncClient

async def main():
    async with AsyncClient(api_key="svcpass_...") as client:
        secrets = await client.secrets.list()
        for s in secrets.data:
            print(s.name)

asyncio.run(main())

Errors

All errors are subclasses of unitysvc_py.UnitysvcSDKError:

from unitysvc_py import (
    UnitysvcSDKError,
    AuthenticationError,   # 401
    PermissionError,       # 403
    NotFoundError,         # 404
    ValidationError,       # 400, 422
    ConflictError,         # 409
    RateLimitError,        # 429
    ServerError,           # 5xx
    APIError,              # base for everything above
)

CLI: usvc

The CLI follows the SDK's configuration — set UNITYSVC_API_KEY (and optionally UNITYSVC_API_URL) and you can run:

usvc env                              # show which env vars the SDK will pick up

# Secrets
usvc secrets list                     # list secrets
usvc secrets set NAME --value V       # create or update a secret by name
usvc secrets delete NAME              # delete a secret by name

# Service aliases
usvc aliases list
usvc aliases show ALIAS_ID
usvc aliases delete ALIAS_ID

# Recurrent requests
usvc recurrent-requests list
usvc recurrent-requests show REQUEST_ID
usvc recurrent-requests trigger REQUEST_ID
usvc recurrent-requests delete REQUEST_ID

Every command accepts --api-key and --base-url overrides.

Layout

src/unitysvc_py/
├── client.py          # Client (sync) facade
├── aclient.py         # AsyncClient (async) facade
├── exceptions.py      # UnitysvcSDKError + status-code subclasses
├── _http.py           # internal: unwrap generated Response → typed model or APIError
├── resources/
│   ├── secrets.py             # client.secrets.*
│   ├── aliases.py             # client.aliases.*
│   ├── recurrent_requests.py  # client.recurrent_requests.*
│   ├── asecrets.py            # async mirror
│   ├── aaliases.py            # async mirror
│   └── arecurrent_requests.py # async mirror
├── _generated/        # openapi-python-client output (do not edit by hand)
├── commands/          # Typer command groups for the CLI
│   ├── _helpers.py    #   run_async, async_client, model_list, ...
│   └── secrets.py     #   `usvc secrets {list,set,delete}`
└── cli.py             # `usvc` Typer entry point

Regenerating the API client

The low-level client under src/unitysvc_py/_generated/ is produced by openapi-python-client from a copy of the backend OpenAPI spec at openapi.json. To regenerate after a backend change:

# Requires a sibling checkout of unitysvc/unitysvc
./scripts/generate_client.sh

The script reads ../unitysvc/backend/generated/customer_api.json by default; pass an explicit spec path as the first argument to override.

License

MIT

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

unitysvc_py-0.1.0.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

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

unitysvc_py-0.1.0-py3-none-any.whl (84.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unitysvc_py-0.1.0.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for unitysvc_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fcc84f4f1133ce37f38f1eb6c19adc9c40b060a915a7df7ebe517caf6a2691e7
MD5 e2ca2b698e6b1eb2df54938e4ebd67c8
BLAKE2b-256 d6832c9edc5178cb0e8aa95d9ed1a6940c2c161dd7dfaa54f1ede7dbf94e0d97

See more details on using hashes here.

Provenance

The following attestation bundles were made for unitysvc_py-0.1.0.tar.gz:

Publisher: publish.yml on unitysvc/unitysvc-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: unitysvc_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 84.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for unitysvc_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5556097025b0beef436a4e4859c6e46e1b0a046e0dcbce561a36ab866a57430c
MD5 7defd8d0ac8f44879258ed18ed1377ff
BLAKE2b-256 6b5bd20a1e3c6766dc48c142f662801ee2074a9a4a4c690f632161665706bde3

See more details on using hashes here.

Provenance

The following attestation bundles were made for unitysvc_py-0.1.0-py3-none-any.whl:

Publisher: publish.yml on unitysvc/unitysvc-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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