appsocom 0.6.3__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appsocom-0.8.0/PKG-INFO +119 -0
- appsocom-0.8.0/README.md +100 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/appsocom/__init__.py +472 -16
- appsocom-0.8.0/appsocom.egg-info/PKG-INFO +119 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/pyproject.toml +1 -1
- appsocom-0.8.0/tests/test_sfukit.py +520 -0
- appsocom-0.6.3/PKG-INFO +0 -62
- appsocom-0.6.3/README.md +0 -43
- appsocom-0.6.3/appsocom.egg-info/PKG-INFO +0 -62
- appsocom-0.6.3/tests/test_sfukit.py +0 -172
- {appsocom-0.6.3 → appsocom-0.8.0}/LICENSE +0 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/appsocom.egg-info/SOURCES.txt +0 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/appsocom.egg-info/dependency_links.txt +0 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/appsocom.egg-info/top_level.txt +0 -0
- {appsocom-0.6.3 → appsocom-0.8.0}/setup.cfg +0 -0
appsocom-0.8.0/PKG-INFO
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: appsocom
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Python server SDK for Appsocom Live video calls: join tokens, rooms, moderation and webhook verification
|
|
5
|
+
Author: Appsotech Limited
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://live.appsocom.com
|
|
8
|
+
Project-URL: Documentation, https://docs.appsocom.dev/server-sdks
|
|
9
|
+
Keywords: appsocom,video,calls,webrtc,sfu,cloudflare
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Communications :: Conferencing
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# appsocom (Python)
|
|
21
|
+
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install appsocom
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import os
|
|
30
|
+
from appsocom import SfuKit, SfuKitError, verify_webhook
|
|
31
|
+
|
|
32
|
+
kit = SfuKit("https://api.appsocom.dev", os.environ["APPSOCOM_API_KEY"]) # project API key from the console
|
|
33
|
+
|
|
34
|
+
tok = kit.create_token("class-1", "u_7", name="Ada", role="student", metadata={"seat": 3})
|
|
35
|
+
tok["token"], tok["expiresAt"]
|
|
36
|
+
|
|
37
|
+
kit.set_role("class-1", "u_9", "student") # promote an observer
|
|
38
|
+
kit.mute("class-1", "*", ["mic"], lock=True) # mute everyone, keep them muted
|
|
39
|
+
kit.set_room_metadata("class-1", {"topic": "Fractions"})
|
|
40
|
+
kit.set_track_permissions("class-1", "u_7", {"allowAll": False, "allow": [{"userId": "u_1"}]})
|
|
41
|
+
kit.remove_participant("class-1", "u_8", ban=True)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Errors raise `SfuKitError` with `.status` and `.body`.
|
|
45
|
+
|
|
46
|
+
Webhooks (Flask):
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
@app.post("/appsocom-webhooks")
|
|
50
|
+
def hook():
|
|
51
|
+
event = verify_webhook(os.environ["APPSOCOM_WEBHOOK_SECRET"], request.get_data(), request.headers.get("X-SfuKit-Signature"))
|
|
52
|
+
if event is None:
|
|
53
|
+
return "", 401
|
|
54
|
+
print(event["event"], event["roomId"])
|
|
55
|
+
return "", 204
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## AI assistant
|
|
59
|
+
|
|
60
|
+
Tell the assistant about your app once, mint a token for each signed-in person, and answer its tool calls at your `toolsUrl`:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from appsocom import AssistantToolError, assistant_tools
|
|
64
|
+
|
|
65
|
+
kit.set_assistant_config({
|
|
66
|
+
"name": "Ada",
|
|
67
|
+
"toolsUrl": "https://app.example/assistant-tools",
|
|
68
|
+
"tools": [{"name": "list_students", "description": "Students in a class", "parameters": {"type": "object", "properties": {"cls": {"type": "string"}}}}],
|
|
69
|
+
"appMap": [{"label": "Fees", "path": "/fees", "aliases": ["bursary"]}],
|
|
70
|
+
})
|
|
71
|
+
tok = kit.create_assistant_token(user.id, name=user.name, role=user.role, metadata={"school": user.school_id})
|
|
72
|
+
# give tok["token"] to the browser (@appsocom/react <AssistantPanel>)
|
|
73
|
+
|
|
74
|
+
def list_students(args, call): # runs as the person who asked
|
|
75
|
+
if call["role"] != "teacher":
|
|
76
|
+
raise AssistantToolError("Only teachers can list students.") # the model sees this message
|
|
77
|
+
return db.students(call["metadata"]["school"], args["cls"])
|
|
78
|
+
|
|
79
|
+
tools = assistant_tools(os.environ["APPSOCOM_WEBHOOK_SECRET"], {"list_students": list_students})
|
|
80
|
+
|
|
81
|
+
@app.post("/assistant-tools")
|
|
82
|
+
def assistant_tools_route():
|
|
83
|
+
status, body = tools.handle(request.get_data(), request.headers.get("X-SfuKit-Signature"))
|
|
84
|
+
return body, status, {"Content-Type": "application/json"}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`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`.
|
|
88
|
+
|
|
89
|
+
## AI Tasks, Speech and Videos
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# AI Tasks: one Claude call from your server (a ready-made task, or your own prompt)
|
|
93
|
+
marked = kit.ai_task("mark", {"question": q, "answer": a, "rubric": rubric, "maxScore": 10}, user=student_id)
|
|
94
|
+
marked["json"]["score"], marked["usage"]["credits"]
|
|
95
|
+
draft = kit.ai_complete("Write a two-line welcome for new parents.", tier="standard")
|
|
96
|
+
data = kit.ai_complete("List the dates in this letter: ...", json={"type": "object", "properties": {"dates": {"type": "array"}}})
|
|
97
|
+
with kit.ai_stream("Tell a short story.") as story:
|
|
98
|
+
for piece in story:
|
|
99
|
+
print(piece, end="")
|
|
100
|
+
story.usage # model, tokens, cost, credits
|
|
101
|
+
|
|
102
|
+
# Speech
|
|
103
|
+
audio = kit.text_to_speech("Well done!", language="en") # mp3 bytes
|
|
104
|
+
link = kit.text_to_speech_url("Ẹ káàárọ̀", language="yo", expires_in=3600) # link["url"] plays without your key
|
|
105
|
+
heard = kit.speech_to_text(recording_bytes, content_type="audio/webm", language="ha") # heard["text"]
|
|
106
|
+
|
|
107
|
+
# Videos: an upload link for a browser, or send a file from your server
|
|
108
|
+
upload = kit.create_video_upload(3600, name="Lesson 1", upload_length=size)
|
|
109
|
+
kit.upload_video_file(upload, open("lesson.mp4", "rb"))
|
|
110
|
+
links = kit.video_playback(upload["videoId"]) # links["hls"], links["iframe"], links["thumbnail"]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`ai_complete` and `ai_task` return the API's answer as a dict (`text`, `json`, `usage`); a call the kit refuses (daily limit, no credit) raises `SfuKitError` with the status, and `ai_stream` raises it at once. Settings and reports: `get_ai_settings`, `set_ai_settings`, `get_ai_usage(days)`, `get_ai_audit(day, user)`, `get_speech_usage`, `set_speech_daily_budget`, `get_video_usage`. Videos: `copy_video`, `list_videos`, `get_video`, `update_video`, `delete_video`. See [AI Tasks](https://docs.appsocom.dev/ai-tasks/), [Speech](https://docs.appsocom.dev/speech/) and [Videos](https://docs.appsocom.dev/videos/).
|
|
114
|
+
|
|
115
|
+
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`, `ai_complete`, `ai_task`, `ai_stream`, `get_ai_settings`, `set_ai_settings`, `get_ai_usage`, `get_ai_audit`, `text_to_speech`, `text_to_speech_url`, `speech_to_text`, `get_speech_usage`, `set_speech_daily_budget`, `create_video_upload`, `upload_video_file`, `copy_video`, `list_videos`, `get_video`, `update_video`, `delete_video`, `video_playback`, `get_video_usage`, `health`, `request()`. Standalone: `sign_token`, `verify_webhook`, `sign_webhook`, `assistant_tools`, `verify_assistant_tool_call`.
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
Docs: [docs.appsocom.dev](https://docs.appsocom.dev) · License: MIT
|
appsocom-0.8.0/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# appsocom (Python)
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install appsocom
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import os
|
|
11
|
+
from appsocom import SfuKit, SfuKitError, verify_webhook
|
|
12
|
+
|
|
13
|
+
kit = SfuKit("https://api.appsocom.dev", os.environ["APPSOCOM_API_KEY"]) # project API key from the console
|
|
14
|
+
|
|
15
|
+
tok = kit.create_token("class-1", "u_7", name="Ada", role="student", metadata={"seat": 3})
|
|
16
|
+
tok["token"], tok["expiresAt"]
|
|
17
|
+
|
|
18
|
+
kit.set_role("class-1", "u_9", "student") # promote an observer
|
|
19
|
+
kit.mute("class-1", "*", ["mic"], lock=True) # mute everyone, keep them muted
|
|
20
|
+
kit.set_room_metadata("class-1", {"topic": "Fractions"})
|
|
21
|
+
kit.set_track_permissions("class-1", "u_7", {"allowAll": False, "allow": [{"userId": "u_1"}]})
|
|
22
|
+
kit.remove_participant("class-1", "u_8", ban=True)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Errors raise `SfuKitError` with `.status` and `.body`.
|
|
26
|
+
|
|
27
|
+
Webhooks (Flask):
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
@app.post("/appsocom-webhooks")
|
|
31
|
+
def hook():
|
|
32
|
+
event = verify_webhook(os.environ["APPSOCOM_WEBHOOK_SECRET"], request.get_data(), request.headers.get("X-SfuKit-Signature"))
|
|
33
|
+
if event is None:
|
|
34
|
+
return "", 401
|
|
35
|
+
print(event["event"], event["roomId"])
|
|
36
|
+
return "", 204
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## AI assistant
|
|
40
|
+
|
|
41
|
+
Tell the assistant about your app once, mint a token for each signed-in person, and answer its tool calls at your `toolsUrl`:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from appsocom import AssistantToolError, assistant_tools
|
|
45
|
+
|
|
46
|
+
kit.set_assistant_config({
|
|
47
|
+
"name": "Ada",
|
|
48
|
+
"toolsUrl": "https://app.example/assistant-tools",
|
|
49
|
+
"tools": [{"name": "list_students", "description": "Students in a class", "parameters": {"type": "object", "properties": {"cls": {"type": "string"}}}}],
|
|
50
|
+
"appMap": [{"label": "Fees", "path": "/fees", "aliases": ["bursary"]}],
|
|
51
|
+
})
|
|
52
|
+
tok = kit.create_assistant_token(user.id, name=user.name, role=user.role, metadata={"school": user.school_id})
|
|
53
|
+
# give tok["token"] to the browser (@appsocom/react <AssistantPanel>)
|
|
54
|
+
|
|
55
|
+
def list_students(args, call): # runs as the person who asked
|
|
56
|
+
if call["role"] != "teacher":
|
|
57
|
+
raise AssistantToolError("Only teachers can list students.") # the model sees this message
|
|
58
|
+
return db.students(call["metadata"]["school"], args["cls"])
|
|
59
|
+
|
|
60
|
+
tools = assistant_tools(os.environ["APPSOCOM_WEBHOOK_SECRET"], {"list_students": list_students})
|
|
61
|
+
|
|
62
|
+
@app.post("/assistant-tools")
|
|
63
|
+
def assistant_tools_route():
|
|
64
|
+
status, body = tools.handle(request.get_data(), request.headers.get("X-SfuKit-Signature"))
|
|
65
|
+
return body, status, {"Content-Type": "application/json"}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`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`.
|
|
69
|
+
|
|
70
|
+
## AI Tasks, Speech and Videos
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# AI Tasks: one Claude call from your server (a ready-made task, or your own prompt)
|
|
74
|
+
marked = kit.ai_task("mark", {"question": q, "answer": a, "rubric": rubric, "maxScore": 10}, user=student_id)
|
|
75
|
+
marked["json"]["score"], marked["usage"]["credits"]
|
|
76
|
+
draft = kit.ai_complete("Write a two-line welcome for new parents.", tier="standard")
|
|
77
|
+
data = kit.ai_complete("List the dates in this letter: ...", json={"type": "object", "properties": {"dates": {"type": "array"}}})
|
|
78
|
+
with kit.ai_stream("Tell a short story.") as story:
|
|
79
|
+
for piece in story:
|
|
80
|
+
print(piece, end="")
|
|
81
|
+
story.usage # model, tokens, cost, credits
|
|
82
|
+
|
|
83
|
+
# Speech
|
|
84
|
+
audio = kit.text_to_speech("Well done!", language="en") # mp3 bytes
|
|
85
|
+
link = kit.text_to_speech_url("Ẹ káàárọ̀", language="yo", expires_in=3600) # link["url"] plays without your key
|
|
86
|
+
heard = kit.speech_to_text(recording_bytes, content_type="audio/webm", language="ha") # heard["text"]
|
|
87
|
+
|
|
88
|
+
# Videos: an upload link for a browser, or send a file from your server
|
|
89
|
+
upload = kit.create_video_upload(3600, name="Lesson 1", upload_length=size)
|
|
90
|
+
kit.upload_video_file(upload, open("lesson.mp4", "rb"))
|
|
91
|
+
links = kit.video_playback(upload["videoId"]) # links["hls"], links["iframe"], links["thumbnail"]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`ai_complete` and `ai_task` return the API's answer as a dict (`text`, `json`, `usage`); a call the kit refuses (daily limit, no credit) raises `SfuKitError` with the status, and `ai_stream` raises it at once. Settings and reports: `get_ai_settings`, `set_ai_settings`, `get_ai_usage(days)`, `get_ai_audit(day, user)`, `get_speech_usage`, `set_speech_daily_budget`, `get_video_usage`. Videos: `copy_video`, `list_videos`, `get_video`, `update_video`, `delete_video`. See [AI Tasks](https://docs.appsocom.dev/ai-tasks/), [Speech](https://docs.appsocom.dev/speech/) and [Videos](https://docs.appsocom.dev/videos/).
|
|
95
|
+
|
|
96
|
+
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`, `ai_complete`, `ai_task`, `ai_stream`, `get_ai_settings`, `set_ai_settings`, `get_ai_usage`, `get_ai_audit`, `text_to_speech`, `text_to_speech_url`, `speech_to_text`, `get_speech_usage`, `set_speech_daily_budget`, `create_video_upload`, `upload_video_file`, `copy_video`, `list_videos`, `get_video`, `update_video`, `delete_video`, `video_playback`, `get_video_usage`, `health`, `request()`. Standalone: `sign_token`, `verify_webhook`, `sign_webhook`, `assistant_tools`, `verify_assistant_tool_call`.
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
100
|
+
Docs: [docs.appsocom.dev](https://docs.appsocom.dev) · License: MIT
|