scriptivox 0.1.0__py3-none-any.whl
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.
- scriptivox/__init__.py +145 -0
- scriptivox/_async_client.py +428 -0
- scriptivox/_client.py +437 -0
- scriptivox/_common.py +293 -0
- scriptivox/_error_codes.py +190 -0
- scriptivox/_exceptions.py +196 -0
- scriptivox/_types.py +473 -0
- scriptivox/_version.py +1 -0
- scriptivox/_webhooks.py +108 -0
- scriptivox/py.typed +0 -0
- scriptivox-0.1.0.dist-info/METADATA +235 -0
- scriptivox-0.1.0.dist-info/RECORD +14 -0
- scriptivox-0.1.0.dist-info/WHEEL +4 -0
- scriptivox-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: scriptivox
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the Scriptivox transcription API: upload, transcribe, wait, export SRT/VTT/text, list, and verify webhooks.
|
|
5
|
+
Project-URL: Homepage, https://www.scriptivox.com
|
|
6
|
+
Project-URL: Documentation, https://platform.scriptivox.com/docs/quickstart
|
|
7
|
+
Project-URL: Repository, https://github.com/SparkleOfficial/scriptivox-python
|
|
8
|
+
Project-URL: Issues, https://github.com/SparkleOfficial/scriptivox-python/issues
|
|
9
|
+
Author-email: Scriptivox <support@scriptivox.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,asr,diarization,scriptivox,sdk,speech-to-text,srt,subtitles,transcription,vtt
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Requires-Dist: httpx<1,>=0.23
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Scriptivox Python SDK
|
|
33
|
+
|
|
34
|
+
The official Python client for the [Scriptivox transcription API](https://platform.scriptivox.com/docs/quickstart). Upload a file or pass a link, wait for the transcript, export SRT, VTT or text, list your jobs and verify webhooks. Sync and asyncio clients, typed responses and one exception class per error code.
|
|
35
|
+
|
|
36
|
+
- Python 3.9 or newer. One dependency: [httpx](https://www.python-httpx.org/).
|
|
37
|
+
- Every submit carries an `Idempotency-Key`, so a retried call never starts a second job.
|
|
38
|
+
- Large files are streamed from disk, never read into memory.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install scriptivox
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quickstart
|
|
47
|
+
|
|
48
|
+
Create an API key on the [API Keys page](https://platform.scriptivox.com/platform/keys) and add balance on the [Billing page](https://platform.scriptivox.com/platform/billing).
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from scriptivox import Scriptivox
|
|
52
|
+
|
|
53
|
+
client = Scriptivox() # reads SCRIPTIVOX_API_KEY, or pass api_key="sk_live_..."
|
|
54
|
+
|
|
55
|
+
job = client.transcribe(file="meeting.mp3", language="en")
|
|
56
|
+
done = client.wait(job["id"])
|
|
57
|
+
print(done["result"]["full_transcript"])
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
From a public link (direct file links, Google Drive, Dropbox and OneDrive share links):
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
job = client.transcribe(url="https://example.com/podcast.mp3", diarize=True, speaker_count=2)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Pass `language` when you know it: it is faster and more accurate than auto-detection. Omit it to auto-detect.
|
|
67
|
+
|
|
68
|
+
## Captions and plain text
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
srt = client.get(job["id"], format="srt", max_words=4)
|
|
72
|
+
vtt = client.get(job["id"], format="vtt", include_speakers=True)
|
|
73
|
+
text = client.get(job["id"], format="text", include_timestamps=True)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`format="json"` (the default) returns the whole job. The caption options are `max_words`, `max_chars`, `max_duration`, `sentence_aware`, `include_speakers`, `strip_chars` and, for text, `include_timestamps`. See [caption export](https://platform.scriptivox.com/docs/api-reference#get-result).
|
|
77
|
+
|
|
78
|
+
## Upload with progress
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
def show(p):
|
|
82
|
+
print(f"{p.percent:5.1f}% {p.loaded}/{p.total} bytes")
|
|
83
|
+
|
|
84
|
+
upload = client.upload("lecture.mp4", on_progress=show)
|
|
85
|
+
job = client.transcribe(upload_id=upload["upload_id"])
|
|
86
|
+
# or in one call:
|
|
87
|
+
job = client.transcribe(file="lecture.mp4", on_upload_progress=show)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`file` can be a path, `bytes`, or a binary file object (`open(path, "rb")`). For bytes or a stream without a name, pass `filename="audio.mp3"`. A non-seekable stream also needs `size=`. Filenames are made ASCII-safe for you (`Réunion.mp3` is sent as `Reunion.mp3`).
|
|
91
|
+
|
|
92
|
+
## Waiting
|
|
93
|
+
|
|
94
|
+
`wait(id)` polls until the job ends. It waits 2 s between polls at first, growing to 10 s, and honours `Retry-After` when rate-limited. It returns the completed job. A job that fails raises `TranscriptionFailedError`, whose `code` is the job's `error.code`:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from scriptivox import TranscriptionFailedError
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
done = client.wait(job["id"], timeout=3600)
|
|
101
|
+
except TranscriptionFailedError as e:
|
|
102
|
+
print(e.code, e.transcription["error"]["message"]) # e.g. URL_NOT_ACCESSIBLE
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Failed and cancelled jobs cost nothing. Prefer webhooks to polling for long files.
|
|
106
|
+
|
|
107
|
+
## Listing, cancelling, deleting, balance
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
for t in client.list(status="completed"): # follows the cursor page by page
|
|
111
|
+
print(t["id"], t["audio_duration_seconds"])
|
|
112
|
+
|
|
113
|
+
client.cancel(job_id) # before transcription starts; not charged
|
|
114
|
+
client.delete(job_id) # a finished job and its transcript
|
|
115
|
+
b = client.balance()
|
|
116
|
+
print(b["available_cents"], b["auto_topup"]["enabled"])
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`list()` takes `status`, `from_`, `to` (datetime or ISO string), `limit` (page size) and `order`. Items leave out `result`; `get(id)` has it.
|
|
120
|
+
|
|
121
|
+
## Webhooks
|
|
122
|
+
|
|
123
|
+
Pass `webhook_url` when you submit, and check every request with `verify_webhook`. It needs the **raw** body, your key's webhook signing secret (`whsec_…`, on the API Keys page) and the request headers. It refuses a bad signature and a timestamp more than 5 minutes old.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
import os
|
|
127
|
+
from fastapi import FastAPI, Request, Response
|
|
128
|
+
from scriptivox import verify_webhook, WebhookVerificationError
|
|
129
|
+
|
|
130
|
+
app = FastAPI()
|
|
131
|
+
|
|
132
|
+
@app.post("/scriptivox")
|
|
133
|
+
async def scriptivox_webhook(request: Request):
|
|
134
|
+
try:
|
|
135
|
+
event = verify_webhook(await request.body(), request.headers, os.environ["SCRIPTIVOX_WEBHOOK_SECRET"])
|
|
136
|
+
except WebhookVerificationError:
|
|
137
|
+
return Response(status_code=400)
|
|
138
|
+
delivery_id = request.headers["x-scriptivox-delivery"] # the same on every retry: skip ones you have handled
|
|
139
|
+
if event["event"] == "transcription.completed":
|
|
140
|
+
print(event["transcription_id"], event["result"]["full_transcript"][:80])
|
|
141
|
+
elif event["event"] == "transcription.failed":
|
|
142
|
+
print(event["transcription_id"], event["error"]["code"])
|
|
143
|
+
return Response(status_code=200)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Flask: `verify_webhook(request.get_data(), request.headers, secret)`. Django: `verify_webhook(request.body, request.headers, secret)`.
|
|
147
|
+
|
|
148
|
+
`client.test_webhook("https://your.server/scriptivox")` sends a signed `webhook.test` event and tells you what your server answered. `client.resend_webhook(job_id)` sends a finished job's final event again.
|
|
149
|
+
|
|
150
|
+
## Errors
|
|
151
|
+
|
|
152
|
+
Every error extends `ScriptivoxError`. When the API answers with an error you get an `APIError` subclass named after its `error.code`, under a class for its HTTP status:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from scriptivox import APIError, PaymentRequiredError, RateLimitExceededError, ZeroBalanceError
|
|
156
|
+
|
|
157
|
+
try:
|
|
158
|
+
client.transcribe(url="https://example.com/a.mp3")
|
|
159
|
+
except ZeroBalanceError:
|
|
160
|
+
print("Add funds on the Billing page")
|
|
161
|
+
except RateLimitExceededError as e:
|
|
162
|
+
print("Too many jobs in progress:", e.error.get("in_flight"), "of", e.error.get("limit"))
|
|
163
|
+
except APIError as e:
|
|
164
|
+
print(e.status, e.code, e.message, e.request_id) # quote request_id to support
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
| Class | When |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `BadRequestError` (400): `InvalidRequestError`, `InvalidFilenameError`, `InvalidMediaFormatError`, … | The request is wrong; fix it, do not retry |
|
|
170
|
+
| `AuthenticationError` (401): `InvalidApiKeyError`, `ApiKeyRevokedError` | The key is missing, wrong or revoked |
|
|
171
|
+
| `PaymentRequiredError` (402): `InsufficientBalanceError`, `ZeroBalanceError` | Add balance |
|
|
172
|
+
| `NotFoundError` (404): `TranscriptionNotFoundError`, `UploadNotFoundError` | Wrong id |
|
|
173
|
+
| `ConflictError` (409), `IdempotencyKeyLockedError` | Not allowed in the job's current state |
|
|
174
|
+
| `RateLimitError` (429): `RateLimitExceededError` | Too many requests, or too many jobs in progress |
|
|
175
|
+
| `InternalServerError` (5xx), `ServiceUnavailableError` (503): `MaintenanceError` | Our side; safe to retry |
|
|
176
|
+
| `APIConnectionError`, `APITimeoutError` | No answer |
|
|
177
|
+
| `UploadFailedError` | The file upload itself failed |
|
|
178
|
+
| `TranscriptionFailedError` | `wait()`: the job ended failed |
|
|
179
|
+
| `WaitTimeoutError` | `wait()`: still running at the timeout |
|
|
180
|
+
| `WebhookVerificationError` | `verify_webhook()`: not a genuine, fresh webhook |
|
|
181
|
+
|
|
182
|
+
The full list of codes is in the [API reference](https://platform.scriptivox.com/docs/api-reference#error-codes).
|
|
183
|
+
|
|
184
|
+
## Retries, timeouts and idempotency
|
|
185
|
+
|
|
186
|
+
- Requests that are safe to repeat (reads, deletes, cancels and submits with an `Idempotency-Key`) are retried up to 2 times after a dropped connection or a 5xx, waiting longer before each try (0.5 s, 1 s, 2 s, …).
|
|
187
|
+
- A `429` or `503` with `Retry-After` is retried after that many seconds, if it is 60 s or less. A `429` without `Retry-After` (the jobs-in-progress cap) is raised at once.
|
|
188
|
+
- `upload()` and `transcribe()` send a new random `Idempotency-Key` per call, reused on the SDK's own retries. Pass `idempotency_key=` (for example your own record id) to make a retry after a crash safe too.
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
client = Scriptivox(max_retries=4, timeout=30.0) # timeout per request, in seconds
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## asyncio
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
import asyncio
|
|
198
|
+
from scriptivox import AsyncScriptivox
|
|
199
|
+
|
|
200
|
+
async def main():
|
|
201
|
+
async with AsyncScriptivox() as client:
|
|
202
|
+
job = await client.transcribe(file="meeting.mp3", language="en")
|
|
203
|
+
done = await client.wait(job["id"])
|
|
204
|
+
async for t in client.list(status="completed"):
|
|
205
|
+
print(t["id"])
|
|
206
|
+
|
|
207
|
+
asyncio.run(main())
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Configuration
|
|
211
|
+
|
|
212
|
+
| Setting | Argument | Environment variable | Default |
|
|
213
|
+
| --- | --- | --- | --- |
|
|
214
|
+
| API key | `api_key` | `SCRIPTIVOX_API_KEY` | none (required) |
|
|
215
|
+
| Base URL | `base_url` | `SCRIPTIVOX_BASE_URL` | `https://api.scriptivox.com` |
|
|
216
|
+
| Retries | `max_retries` | | 2 |
|
|
217
|
+
| Request timeout (s) | `timeout` | | 60 |
|
|
218
|
+
| Your own httpx client | `http_client` | | a new `httpx.Client` |
|
|
219
|
+
|
|
220
|
+
Responses are plain dicts, typed with `TypedDict`s generated from the [OpenAPI document](https://platform.scriptivox.com/openapi.json) (`scriptivox.Transcription`, `scriptivox.Balance`, …).
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
python scripts/generate.py # regenerate _types.py and _error_codes.py from openapi/openapi.json
|
|
226
|
+
python scripts/generate.py --fetch # refresh the snapshot from platform.scriptivox.com first
|
|
227
|
+
pip install -e '.[dev]' && pytest # unit tests, no network
|
|
228
|
+
|
|
229
|
+
# integration tests against a test deployment
|
|
230
|
+
SCRIPTIVOX_API_KEY=sk_live_... SCRIPTIVOX_BASE_URL=https://api-test.scriptivox.com pytest tests/test_integration.py
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
scriptivox/__init__.py,sha256=qTnmgcSL0MerTkFaAEeiuOrNfmUu1H6RwBF0WgV1ICA,3865
|
|
2
|
+
scriptivox/_async_client.py,sha256=t5S9TOK3FUUDwZIIbEt01GgVF7XPiynSgJarhJt4_kw,18797
|
|
3
|
+
scriptivox/_client.py,sha256=0ZFbDJbWJqqLrHJBdOhTalwoQDU21XRY8jpxjbXiIOs,18611
|
|
4
|
+
scriptivox/_common.py,sha256=l2egZhLTsNBwwII1gwAf6fXW-01nlX95_l1dpXLQH38,11002
|
|
5
|
+
scriptivox/_error_codes.py,sha256=UniAZ2oj5MssgWlk8DKhvQAAfFBzaH0QqNvreK1wRr0,9769
|
|
6
|
+
scriptivox/_exceptions.py,sha256=HgT3P8gtkT7H5dGBYAk5aUtv9cZwIOqs-h7T1nnVu48,6739
|
|
7
|
+
scriptivox/_types.py,sha256=acV6HmczRUyjWuhfo5w5vn6IKJ44R0mxTUdpu8pxawU,21872
|
|
8
|
+
scriptivox/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
9
|
+
scriptivox/_webhooks.py,sha256=IMNesrZWq59chuuQnd3WYMDuZdKM-cpwnz0i8swAE-k,4813
|
|
10
|
+
scriptivox/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
scriptivox-0.1.0.dist-info/METADATA,sha256=3KUIF8VGNUYHuPMbLgju3124SxYNB_Vtl0vOYK5klZ8,10575
|
|
12
|
+
scriptivox-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
13
|
+
scriptivox-0.1.0.dist-info/licenses/LICENSE,sha256=_Mx366nV5Knx3a5n1h672BNHryY0MVnqCXH9qoKY71c,1067
|
|
14
|
+
scriptivox-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Scriptivox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|