Metadata-Version: 2.5
Name: dtelecom-server-sdk
Version: 0.1.0
Summary: Async Python client for dTelecom Cloud
Project-URL: Homepage, https://dtelecom.org/
Project-URL: Documentation, https://docs.dtelecom.org/
Project-URL: Source, https://github.com/dTelecom/server-sdk-python
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Requires-Python: >=3.11
Requires-Dist: base58<3,>=2.1
Requires-Dist: httpx<1,>=0.27
Requires-Dist: protobuf<8,>=5.29
Requires-Dist: pydantic<3,>=2.8
Requires-Dist: pyjwt[crypto]<3,>=2.10
Requires-Dist: websockets<17,>=15
Provides-Extra: webhooks
Requires-Dist: solders<1,>=0.23; extra == 'webhooks'
Description-Content-Type: text/markdown

# dTelecom Cloud server SDK for Python

Use Python 3.11 or later to issue room grants, administer participants, verify incoming webhooks, and use dTelecom speech and AI services. Set `DTELECOM_API_KEY`, `DTELECOM_API_SECRET`, and `DTELECOM_CLOUD_URL` in your backend environment.

```python
from dtelecom_server import CloudClient

async def issue(room: str, identity: str) -> dict:
    async with CloudClient() as cloud:
        grant = await cloud.create_token(room, identity, ttl="10m")
        return grant.client_fields()
```

Pass the returned token, wsUrl and fallbackUrls to the room client. Use the backend-only session ID and expiry to schedule extensions. Keep a client open across requests in a long-running application and call `await cloud.aclose()` at shutdown.

For a Solana registry-backed webhook verifier, install the `webhooks` extra. The receiver accepts the original raw request body and Authorization header. [Cloud API reference](https://docs.dtelecom.org/reference/http-api/)

## Room administration and session charges

```python
async with CloudClient() as cloud:
    rooms = cloud.room_service()
    for participant in await rooms.list_participants("demo"):
        print(participant.identity)
    await rooms.send_data("demo", b"Starting in one minute", topic="announcement")
    charges = await cloud.list_sessions("demo", limit=20)
    print(charges.total_usd)
```

The SDK uses room-scoped admin grants from Cloud and sends node operations to the returned API URLs. Rooms spanning multiple nodes return one participant per SID. The SDK prefers the local owner’s record over its relayed copies and sends participant changes to that owner. If the owner cannot be located after refreshing node membership, the operation reports an error. Each participant or AI service session has its own session ID. Use `get_session` to read its status and final charge.

## Speech and AI services

```python
from uuid import uuid4

async with CloudClient() as cloud:
    result = await cloud.translate("Good morning", "es", source="en", idempotency_key=uuid4().hex)
    if result.status == "completed":
        print(result.result.translated_text)
    else:
        print(result.id)
```

Use `get_translation` to check a pending translation. The `stt` and `tts` clients issue and extend streaming credentials. Use `transcriptions` and `wav` for file jobs, `vision` for snapshots and `moderation` for audio, frames or a ticketed WebSocket. Supply one idempotency key per logical job or inference request and keep it across retries.

## Verify a webhook

```python
from dtelecom_server import WebhookReceiver

async with WebhookReceiver() as receiver:
    event = await receiver.receive(raw_request_body, authorization_header)
    print(event.event)
```

The receiver verifies the node's Ed25519 signature, registry membership and the exact request body's signed checksum. Pass the body bytes before JSON parsing. A custom async `registered_node` callback can supply your trusted registry lookup.
