Skip to content

feat(python): moqt の Python (asyncio) バインディングを追加する - #349

Open
yuki-uchida wants to merge 1 commit into
masterfrom
feat/python-bindings
Open

feat(python): moqt の Python (asyncio) バインディングを追加する#349
yuki-uchida wants to merge 1 commit into
masterfrom
feat/python-bindings

Conversation

@yuki-uchida

Copy link
Copy Markdown
Collaborator

概要

bindings/python に PyO3 + maturin 製の moqt モジュールを追加しました。
#348(拡張ヘッダ修正)の上に積んでいます。往復テストが拡張ヘッダの到達を検証するためです。

やったこと

  • connect(url) / listen(port, cert, key)Session、4 種の受信リクエスト(accept() / reject()、ハンドラの drop でエラー応答)、TrackReaderMoqObjectTrackWriter を公開
  • TrackReader は初回 read まで accept_data_receiver を遅延させる(moqt 側が最初の object 到着まで待つため、subscribe() / accept() が publisher の送信までブロックするのを避ける)。listen() は quinn が ambient runtime で bind するため tokio runtime に enter してから endpoint を作る
  • pyo3 / pyo3-async-runtimes の ADR、AGENTS.md のコンポーネント表、moqt.pyi、README を追加

やらないこと

  • wheel の配布・CI でのビルド。datagram track(エラーで拒否)、FETCH / TRACK_STATUS / SUBSCRIBE_UPDATE の公開

影響範囲

  • cargo build / clippy に Python インタプリタが必要になる(pyo3-build-config)。GitHub の ubuntu runner には python3 があるため CI 設定は変えていない
  • [lib] test = false のため cargo test --workspace にこのクレートのテストは含まれない

テスト

  • pytest 6 件: in-process サーバーに対して subscribe 往復(QUIC / WebTransport)、publish 往復、reject が RuntimeError になること、namespace 往復、二重応答の拒否
  • cargo clippy --workspace --all-targets --all-features -- -D warnings / cargo fmt --all -- --check: 警告なし。cargo test --workspace: 全通過

備考

  • async メソッドは coroutine ではなく asyncio.Future を返すため、asyncio.create_task ではなく ensure_future を使う必要がある(README に記載)

bindings/python wraps Session<DUAL> so one Python type covers raw QUIC
and WebTransport: connect(url) picks the transport by scheme and
listen(port, cert, key) accepts both. Every operation returns an asyncio
awaitable via pyo3-async-runtimes.

Exposed surface: Session (subscribe / publish / publish_namespace /
subscribe_namespace / events), the inbound requests SubscribeRequest,
PublishRequest, PublishNamespaceRequest and SubscribeNamespaceRequest
with accept() / reject(), Disconnected / ProtocolViolation, TrackReader
yielding MoqObject (group_id, object_id, payload, immutable_extensions)
and TrackWriter. Other SessionEvent variants are skipped; their handlers
answer with an error when dropped.

TrackReader creates the moqt reader lazily on the first read because the
data receiver only resolves once the first object has arrived; otherwise
subscribe() and PublishRequest.accept() would block until the publisher
sends. listen() enters the tokio runtime because quinn binds its socket
through the ambient runtime and the call comes from plain Python code.

The crate disables its cargo test harness (extension modules cannot link
as test binaries); pytest covers subscribe, publish, namespace and
rejection round trips over both transports against an in-process
server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant