Python bindings for the Media over QUIC Rust crates: real-time pub/sub with built-in caching, fan-out, and prioritization.
Project description
moq-rs
Python bindings for the Media over QUIC Rust crates: real-time pub/sub with built-in caching, fan-out, and prioritization, on top of QUIC.
moq-rs wraps the auto-generated moq-ffi UniFFI bindings with a Pythonic API: no Moq prefixes, async iterators, context managers, and simplified connection setup. At session setup it negotiates either the moq-lite or moq-transport wire protocol.
Installation
pip install moq-rs
The distribution is moq-rs; the import name is moq.
Quick Start
Subscribe to a stream
import asyncio
import moq
async def main():
async with moq.Client("https://relay.quic.video") as client:
async for announcement in client.announced():
catalog = await announcement.broadcast.catalog()
for name in catalog.audio:
async for frame in announcement.broadcast.subscribe_media(name):
print(f"Got frame: {len(frame.payload)} bytes, ts={frame.timestamp_us}")
asyncio.run(main())
Publish a stream
import asyncio
import moq
async def main():
async with moq.Client("https://relay.quic.video") as client:
broadcast = moq.BroadcastProducer()
# Publish an Opus audio track (init bytes from your encoder)
audio = broadcast.publish_media("opus", opus_init_bytes)
client.publish("my-stream", broadcast)
# Write frames
audio.write_frame(payload, timestamp_us=0)
audio.write_frame(payload, timestamp_us=20000)
# Clean up
audio.finish()
broadcast.finish()
asyncio.run(main())
Host a server
import asyncio
import moq_lite as moq
async def main():
async with moq.Server("127.0.0.1:4443", tls_generate=["localhost"]) as server:
broadcast = moq.BroadcastProducer()
track = broadcast.publish_track("events")
server.publish("hello", broadcast)
print(f"listening on https://{server.local_addr}")
sessions = []
async for request in server:
print(f" + {request.transport} from {request.url}")
sessions.append(await request.ok())
asyncio.run(main())
Reject a request instead of accepting it with await request.close(403).
Advanced: Manual origin wiring
For full control over the origin topology:
import moq
origin = moq.OriginProducer()
client = moq.Client(
"https://relay.quic.video",
publish=origin,
subscribe=origin,
)
API
Connection
Client(url, *, tls_verify=True, bind=None, publish=None, subscribe=None). Async context manager for connecting to a relay.Server(bind="[::]:443", *, tls_cert=(), tls_key=(), tls_generate=(), publish=None, subscribe=None). Async context manager + async iterator of incomingRequests..local_addr. The bound address (useful when binding to port0)..cert_fingerprints(). SHA-256 fingerprints of the configured TLS certificates, forserverCertificateHashesbrowser cert pinning..publish(path, broadcast). Publish a broadcast to be served.
Request. An incoming session, yielded byasync for request in server..url,.transport. Properties..set_publish(origin),.set_consume(origin). Per-request overrides.await .ok(). Complete the handshake, returns a session (hold it to keep the connection alive).await .close(code). Reject with an HTTP status code..cancel(). Cancel an in-flightok()/close()call.
Publishing
BroadcastProducer(). Create a broadcast to publish tracks into..publish_media(format, init) → MediaProducer.finish()
MediaProducer. Write frames to a track..write_frame(payload, timestamp_us).finish()
Subscribing
BroadcastConsumer. Subscribe to tracks within a broadcast..subscribe_catalog() → CatalogConsumer.subscribe_media(name, max_latency_ms=10000) → MediaConsumerawait .catalog() → Catalog(convenience)
CatalogConsumer. Async iterator ofCatalog.MediaConsumer. Async iterator ofFrame.
Origin (advanced)
OriginProducer(). Manage broadcast announcements..consume() → OriginConsumer.publish(path, broadcast)
OriginConsumer. Discover broadcasts..announced(prefix) → Announced(async iterator).announced_broadcast(path) → AnnouncedBroadcast(awaitable)
Types
Catalog..audio: dict[str, Audio],.video: dict[str, Video],.display,.rotation,.flip.Frame..payload: bytes,.timestamp_us: int,.keyframe: bool.Audio..codec,.sample_rate,.channel_count,.bitrate,.description.Video..codec,.coded: Dimensions,.display_ratio,.bitrate,.framerate,.description.Dimensions..width: int,.height: int.
See Also
- moq-ffi. The Rust crate that produces the UniFFI bindings vendored as
moq._uniffi. - MoQ project. Full monorepo with Rust server, TypeScript browser lib, and more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moq_rs-0.2.12.tar.gz.
File metadata
- Download URL: moq_rs-0.2.12.tar.gz
- Upload date:
- Size: 375.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53fd46732874c436a2b03d570e4a3b5466b34c3b924133f6ec8976a51dea8a3a
|
|
| MD5 |
3510b1770c06be0dca5ad6312eed75fd
|
|
| BLAKE2b-256 |
48dd10ccdd6ea6dc075b9f99b7e54dfe8c68db1035ac87e032e993ea3621f6d7
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12.tar.gz:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12.tar.gz -
Subject digest:
53fd46732874c436a2b03d570e4a3b5466b34c3b924133f6ec8976a51dea8a3a - Sigstore transparency entry: 1624885402
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file moq_rs-0.2.12-py3-none-win_amd64.whl.
File metadata
- Download URL: moq_rs-0.2.12-py3-none-win_amd64.whl
- Upload date:
- Size: 5.1 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83bd6cdaa753f7e14685da4a58f92f772b6bdb2a53cd64ee3bba0597edeb7ffd
|
|
| MD5 |
1cd3a760358099f6a9d2b33d47a6a742
|
|
| BLAKE2b-256 |
d848273383a5d1adb40dbd63cd280496a6fc3ceb206c5fd3c275cc869b34a700
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12-py3-none-win_amd64.whl:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12-py3-none-win_amd64.whl -
Subject digest:
83bd6cdaa753f7e14685da4a58f92f772b6bdb2a53cd64ee3bba0597edeb7ffd - Sigstore transparency entry: 1624885686
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file moq_rs-0.2.12-py3-none-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: moq_rs-0.2.12-py3-none-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 3, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a07ae9e763d13ee8437354ba891afffc653af382cfa7533f795617ac2bbf541
|
|
| MD5 |
52276fe7cd00a5b5ca99d9e24d794f2f
|
|
| BLAKE2b-256 |
9aa06243e1502f2a6e9e94aadab5d7bd161b43281c6773ea5a66b45a23f16d25
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12-py3-none-manylinux_2_28_aarch64.whl:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12-py3-none-manylinux_2_28_aarch64.whl -
Subject digest:
8a07ae9e763d13ee8437354ba891afffc653af382cfa7533f795617ac2bbf541 - Sigstore transparency entry: 1624885568
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file moq_rs-0.2.12-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: moq_rs-0.2.12-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.7 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f9580e3c719b657963bb6b3d6eef0714454adbe1c43ba07bc0b367e010353af
|
|
| MD5 |
16210aad05c2cefff28d0d981500cb05
|
|
| BLAKE2b-256 |
21caee6435b3b4cfc45ec006de2a443536d50b9d71784eb8c3734057b3da5a79
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
3f9580e3c719b657963bb6b3d6eef0714454adbe1c43ba07bc0b367e010353af - Sigstore transparency entry: 1624885657
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file moq_rs-0.2.12-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: moq_rs-0.2.12-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.9 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f963129679048702af2b92cf911db92c55e36a248b094e73df7f0c9aec916db
|
|
| MD5 |
61eb9a23b4b7af32623d3e5db8ad1a91
|
|
| BLAKE2b-256 |
9fa5015255846b4e2275770cc3511a1ece6f0989cf35ae4b0b354ceca1d56f16
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12-py3-none-macosx_11_0_arm64.whl:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12-py3-none-macosx_11_0_arm64.whl -
Subject digest:
4f963129679048702af2b92cf911db92c55e36a248b094e73df7f0c9aec916db - Sigstore transparency entry: 1624885625
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file moq_rs-0.2.12-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: moq_rs-0.2.12-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 6.3 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dad75cfa8cca1c07eb49199c44984f37254a968c053f87149e14483a7e2f236
|
|
| MD5 |
e0bb59723be4c92cd881a17daa21db13
|
|
| BLAKE2b-256 |
3adb51ea4bfdea8f5c5583d19ce08d2802c93d1ea974278fa06f2b058d3d54bd
|
Provenance
The following attestation bundles were made for moq_rs-0.2.12-py3-none-macosx_10_12_x86_64.whl:
Publisher:
release-py.yml on moq-dev/moq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
moq_rs-0.2.12-py3-none-macosx_10_12_x86_64.whl -
Subject digest:
2dad75cfa8cca1c07eb49199c44984f37254a968c053f87149e14483a7e2f236 - Sigstore transparency entry: 1624885484
- Sigstore integration time:
-
Permalink:
moq-dev/moq@21206fa7a8667e056c31e05448d38cc50c766e16 -
Branch / Tag:
refs/tags/moq-ffi-v0.2.12 - Owner: https://github.com/moq-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-py.yml@21206fa7a8667e056c31e05448d38cc50c766e16 -
Trigger Event:
push
-
Statement type: