Metadata-Version: 2.4
Name: appsocom
Version: 0.7.0
Summary: Python server SDK for Appsocom Live video calls: join tokens, rooms, moderation and webhook verification
Author: Appsotech Limited
License-Expression: MIT
Project-URL: Homepage, https://live.appsocom.com
Project-URL: Documentation, https://docs.appsocom.dev/server-sdks
Keywords: appsocom,video,calls,webrtc,sfu,cloudflare
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Communications :: Conferencing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# appsocom (Python)

Python server SDK for [Appsocom Live](https://live.appsocom.com): mint join tokens, manage rooms and participants, moderate and verify webhooks. Python 3.9+, standard library only.

```bash
pip install appsocom
```

```python
import os
from appsocom import SfuKit, SfuKitError, verify_webhook

kit = SfuKit("https://api.appsocom.dev", os.environ["APPSOCOM_API_KEY"])  # project API key from the console

tok = kit.create_token("class-1", "u_7", name="Ada", role="student", metadata={"seat": 3})
tok["token"], tok["expiresAt"]

kit.set_role("class-1", "u_9", "student")             # promote an observer
kit.mute("class-1", "*", ["mic"], lock=True)          # mute everyone, keep them muted
kit.set_room_metadata("class-1", {"topic": "Fractions"})
kit.set_track_permissions("class-1", "u_7", {"allowAll": False, "allow": [{"userId": "u_1"}]})
kit.remove_participant("class-1", "u_8", ban=True)
```

Errors raise `SfuKitError` with `.status` and `.body`.

Webhooks (Flask):

```python
@app.post("/appsocom-webhooks")
def hook():
    event = verify_webhook(os.environ["APPSOCOM_WEBHOOK_SECRET"], request.get_data(), request.headers.get("X-SfuKit-Signature"))
    if event is None:
        return "", 401
    print(event["event"], event["roomId"])
    return "", 204
```

## AI assistant

Tell the assistant about your app once, mint a token for each signed-in person, and answer its tool calls at your `toolsUrl`:

```python
from appsocom import AssistantToolError, assistant_tools

kit.set_assistant_config({
    "name": "Ada",
    "toolsUrl": "https://app.example/assistant-tools",
    "tools": [{"name": "list_students", "description": "Students in a class", "parameters": {"type": "object", "properties": {"cls": {"type": "string"}}}}],
    "appMap": [{"label": "Fees", "path": "/fees", "aliases": ["bursary"]}],
})
tok = kit.create_assistant_token(user.id, name=user.name, role=user.role, metadata={"school": user.school_id})
# give tok["token"] to the browser (@appsocom/react <AssistantPanel>)

def list_students(args, call):  # runs as the person who asked
    if call["role"] != "teacher":
        raise AssistantToolError("Only teachers can list students.")  # the model sees this message
    return db.students(call["metadata"]["school"], args["cls"])

tools = assistant_tools(os.environ["APPSOCOM_WEBHOOK_SECRET"], {"list_students": list_students})

@app.post("/assistant-tools")
def assistant_tools_route():
    status, body = tools.handle(request.get_data(), request.headers.get("X-SfuKit-Signature"))
    return body, status, {"Content-Type": "application/json"}
```

`handle()` refuses bad or stale signatures with 401, answers `{"result": ...}` (`"done"` when a tool returns `None`) or `{"error": ...}`, and hides any exception other than `AssistantToolError` as "The tool failed." (pass `on_error=` to see it). Also: `get_assistant_config`, `delete_assistant_conversation(user_id, conversation_id)`, `verify_assistant_tool_call`.

All methods: `create_token`, `get_room`, `list_participants`, `update_room`, `set_room_metadata`, `lock_room`, `close_room`, `update_participant`, `set_permissions`, `set_role`, `set_participant_metadata`, `set_track_permissions`, `remove_participant`, `unban`, `mute`, `admit`, `post_chat`, `lower_hands`, `get_attendance`, `get_attendance_csv`, `clear_attendance`, `start_breakouts`, `end_breakouts`, `move_to_group`, `set_assistant_config`, `get_assistant_config`, `create_assistant_token`, `delete_assistant_conversation`, `health`, `request()`. Standalone: `sign_token`, `verify_webhook`, `sign_webhook`, `assistant_tools`, `verify_assistant_tool_call`.

Self-hosting your own deployment instead? Point `url` at it and pass its admin key; the optional `jwt_secret` signs tokens locally without an HTTP call.

Docs: [docs.appsocom.dev](https://docs.appsocom.dev) · License: MIT
