Skip to content

Commit 0abd334

Browse files
volodstaimiclaude
andcommitted
Rust client for the Transcript Dock API
Async client on reqwest with rustls. Ports the Python client's origin, key, path and idempotency validation, no redirects, no automatic retries, token redaction, text exports and bounded wait_for_job polling. The contract checks in examples/client_check.rs run against the shared loopback fixture through .ci/check.py. Cargo.lock is generated by the first CI run and committed next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0 parents  commit 0abd334

11 files changed

Lines changed: 1538 additions & 0 deletions

File tree

‎.ci/check.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from fixture import Fixture
2+
import os, subprocess, threading
3+
from http.server import ThreadingHTTPServer
4+
Fixture.calls = []
5+
server = ThreadingHTTPServer(('127.0.0.1', 0), Fixture)
6+
thread = threading.Thread(target=server.serve_forever, daemon=True)
7+
thread.start()
8+
try:
9+
env = dict(os.environ, TRANSCRIPTDOCK_TEST_BASE_URL=f'http://127.0.0.1:{server.server_port}')
10+
subprocess.run(['cargo', 'run', '--quiet', '--example', 'client_check'], env=env, check=True, timeout=120)
11+
assert not any('/credential-leak' in path for _, path in Fixture.calls), 'redirect leaked a request'
12+
assert sum(path == '/v1/rate-limit' for _, path in Fixture.calls) == 1, 'unexpected automatic retry'
13+
print(f'{len(Fixture.calls)} local fixture requests checked')
14+
finally:
15+
server.shutdown()
16+
server.server_close()
17+
thread.join()

‎.ci/fixture.py‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""Run SDK contract checks against local fixtures, never production."""
2+
import argparse
3+
import json
4+
import os
5+
from pathlib import Path
6+
import subprocess
7+
import threading
8+
import time
9+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
10+
from urllib.parse import urlsplit, parse_qs
11+
12+
ROOT = Path(__file__).resolve().parents[2]
13+
KEY = 'td_live_fixture_only'
14+
15+
16+
class Fixture(BaseHTTPRequestHandler):
17+
calls = []
18+
19+
def log_message(self, *args):
20+
pass
21+
22+
def do_GET(self): self.respond()
23+
def do_POST(self): self.respond()
24+
def do_DELETE(self): self.respond()
25+
def do_PATCH(self): self.respond()
26+
27+
def respond(self):
28+
self.calls.append((self.command, self.path))
29+
raw = self.rfile.read(int(self.headers.get('Content-Length', '0')))
30+
path = urlsplit(self.path).path
31+
status = 200
32+
content_type = 'application/json; charset=utf-8'
33+
payload = {'id': 'fixture', 'status': 'succeeded', 'result_id': 'transcript', 'future_field': 42,
34+
'words': [{'start_ms': 123, 'end_ms': 456}],
35+
'request': {'method': self.command, 'path': path, 'query': parse_qs(urlsplit(self.path).query),
36+
'body': json.loads(raw) if raw else None,
37+
'idempotency_key': self.headers.get('Idempotency-Key'),
38+
'authorized': self.headers.get('Authorization') == 'Bearer ' + KEY}}
39+
if path == '/v1/redirect':
40+
self.send_response(302)
41+
self.send_header('Location', '/v1/credential-leak')
42+
self.send_header('Content-Length', '0')
43+
self.end_headers()
44+
return
45+
if path == '/v1/rate-limit':
46+
status = 429
47+
payload = {'error': {'code': 'RATE_LIMITED', 'message': KEY, 'retryable': True, 'retry_after_seconds': 4}, 'request_id': 'fixture-request'}
48+
elif path in ('/v1/budget', '/v1/conflict', '/v1/jobs/not-owned'):
49+
status, code = {'/v1/budget': (402, 'BUDGET_EXCEEDED'), '/v1/conflict': (409, 'IDEMPOTENCY_CONFLICT'), '/v1/jobs/not-owned': (404, 'NOT_FOUND')}[path]
50+
payload = {'error': {'code': code, 'message': 'Fixture rejection', 'retryable': False}}
51+
elif path == '/v1/gateway':
52+
status, payload = 502, b'<html>gateway failed</html>'
53+
elif path == '/v1/error-shape':
54+
status, payload = 500, ['not an error object']
55+
elif path == '/v1/malformed':
56+
payload = b'not-json'
57+
elif path == '/v1/array':
58+
payload = []
59+
elif path == '/v1/slow':
60+
time.sleep(.3)
61+
elif path.endswith('/export'):
62+
content_type = 'text/plain; charset=utf-8'
63+
payload = '1\n00:00:00,000 --> 00:00:01,000\nCafé fixture\n'.encode()
64+
elif path.startswith('/v1/jobs/'):
65+
name = path.rsplit('/', 1)[-1]
66+
payload['status'] = name if name in ('succeeded', 'failed', 'cancelled', 'processing') else 'succeeded'
67+
if self.command == 'POST':
68+
status = 202
69+
data = payload if isinstance(payload, bytes) else json.dumps(payload).encode()
70+
try:
71+
self.send_response(status)
72+
self.send_header('Content-Type', content_type)
73+
self.send_header('Content-Length', str(len(data)))
74+
self.end_headers()
75+
self.wfile.write(data)
76+
except (BrokenPipeError, ConnectionResetError):
77+
pass

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

‎.github/workflows/release.yml‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Check and release Rust crate
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
workflow_dispatch:
7+
inputs:
8+
publish:
9+
description: Publish the checked version to crates.io
10+
type: boolean
11+
default: false
12+
permissions:
13+
contents: read
14+
env:
15+
CARGO_TERM_COLOR: always
16+
MSRV: '1.85.0'
17+
STABLE: '1.99.1'
18+
jobs:
19+
format:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
23+
with:
24+
persist-credentials: false
25+
- uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
26+
with:
27+
toolchain: ${{ env.STABLE }}
28+
components: rustfmt
29+
- run: cargo fmt --check
30+
lint:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
34+
with:
35+
persist-credentials: false
36+
- uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
37+
with:
38+
toolchain: ${{ env.STABLE }}
39+
components: clippy
40+
# Bootstrap only: removed once Cargo.lock is committed.
41+
- run: test -f Cargo.lock || cargo generate-lockfile
42+
- run: cargo clippy --locked --all-targets -- -D warnings
43+
test:
44+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
rust: [msrv, stable]
49+
steps:
50+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
51+
with:
52+
persist-credentials: false
53+
- uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
54+
with:
55+
toolchain: ${{ matrix.rust == 'msrv' && env.MSRV || env.STABLE }}
56+
# Bootstrap only: removed once Cargo.lock is committed.
57+
- run: test -f Cargo.lock || cargo generate-lockfile
58+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
59+
if: matrix.rust == 'stable'
60+
with:
61+
name: cargo-lock
62+
path: Cargo.lock
63+
- run: cargo test --locked
64+
- run: python3 .ci/check.py
65+
- run: cargo publish --dry-run --locked --allow-dirty
66+
if: matrix.rust == 'stable'
67+
publish:
68+
if: github.event_name == 'workflow_dispatch' && inputs.publish && github.ref == 'refs/heads/main'
69+
needs: [format, lint, test]
70+
runs-on: ubuntu-latest
71+
environment: crates-io
72+
permissions:
73+
contents: read
74+
id-token: write
75+
steps:
76+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
77+
with:
78+
persist-credentials: false
79+
- uses: dtolnay/rust-toolchain@df2a88e9fe4098bad09cb42c3dec7187f15861fc # master
80+
with:
81+
toolchain: ${{ env.STABLE }}
82+
- uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
83+
id: auth
84+
- run: cargo publish --locked
85+
env:
86+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

‎Cargo.toml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "transcriptdock"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.85"
6+
resolver = "3"
7+
description = "Async client for the Transcript Dock video transcription API with explicit idempotency and bounded polling."
8+
license = "MIT"
9+
authors = ["Transcript Dock <transcriptdock@volods.com>"]
10+
repository = "https://github.com/TranscriptDock/transcriptdock-rust"
11+
homepage = "https://www.transcriptdock.com/docs"
12+
documentation = "https://docs.rs/transcriptdock"
13+
readme = "README.md"
14+
keywords = ["transcription", "transcript", "youtube", "tiktok", "api"]
15+
categories = ["api-bindings", "web-programming::http-client"]
16+
include = ["src/**/*.rs", "examples/**/*.rs", "README.md", "LICENSE", "Cargo.toml"]
17+
18+
[dependencies]
19+
reqwest = { version = "=0.13.5", default-features = false, features = ["rustls", "json"] }
20+
serde_json = "=1.0.154"
21+
tokio = { version = "=1.54.1", features = ["time"] }
22+
url = "=2.5.8"
23+
24+
[dev-dependencies]
25+
tokio = { version = "=1.54.1", features = ["macros", "rt-multi-thread"] }

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Transcript Dock
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.

0 commit comments

Comments
 (0)