Python binding
Status: ✅ verified — the
mediawaypackage inmediaway/is real (pure-Pythonctypesover the C ABI) and the examples inexamples/run against the native libraries: mux/demux roundtrip, real H.264 encode, real camera + mic capture. This README is the DX contract the package implements: context managers, exceptions, Rational-second timestamps, bytes for buffers.
See the C binding README for the underlying C ABI contract (status enums, ownership, thread confinement) — the Python package translates that ABI into idiomatic Python.
What Mediaway is (the capabilities)
A streaming-first media stack. The C ABI currently covers three capabilities (full
detail in ../c/README.md and docs/spec/c-ffi.md):
- Container — mux + demux: sans-io fragmented-MP4 muxer (register video/audio
tracks,
begin()→ live, push packets, flush,poll_bytes(); the muxer never touches files — the caller owns byte I/O) and demuxer (push_bytes,streams(),poll_packet(), optional ClearKey key). Fully real. - Pipeline — auto video encode → fMP4: one call picks the best available OS/GPU
encoder for a config, wires it into an internal MP4 muxer;
finish()returns complete MP4 bytes. Video only — the audio encoder is separate (ABI v2, adr/0003):AudioEncoder.open()streams AAC packets for the caller's own muxer. - Device — capture: camera (CPU frames), microphone/loopback (PCM), hotplug.
Screen capture is
UNSUPPORTEDfrom C today (needs a GPU device handle with no C representation yet) — an honest gap, not a bug.
The real ABI beneath (what the wrapper wraps)
DLLs: mediaway_ffi, mediaway_ffi, mediaway_ffi (built
for x86_64-pc-windows-gnu, see the C README's build recipe). Headers
crates/mediaway-*-ffi/include/mediaway/{container,pipeline,device}.h are the
authoritative layout.
- Opaque handles, all thread-confined (no concurrent calls on one handle).
- Every status is a per-crate enum,
OK = 0; a caught Rust panic poisons the handle.NO_BACKEND/UNSUPPORTEDare expected outcomes, not errors. - Ownership: borrowed inputs valid for the call only (the wrapper must copy in);
owned outputs (
poll_bytesbuffers, demuxed packets/stream info, encodefinishbuffers, polled device frames) must be released via the matching_free— the wrapper's job is to make this automatic (context managers / finalizers). - Handle-consumption traps the wrapper MUST hide:
mediaway_encode_session_openconsumes the encoder unconditionally;mediaway_encode_session_finishconsumes the session. Python can hide this by foldingopenintoEncodeSessionconstruction and makingfinishterminal.
Ideal API — the DX contract
A single mediaway package, pure-Python ctypes glue + idiomatic wrappers.
snake_case everywhere (Python convention beats the C names): Rational,
VideoStreamInfo, AudioStreamInfo, Packet, Codec (enum), VideoFrame;
classes Muxer, Demuxer, EncodeSession, AutoVideoEncoder, VideoCapture,
AudioCapture.
- Context managers:
with Muxer() as m:,with Demuxer() as d:,with EncodeSession(...) as s:—__exit__closes the underlying handle (and, for capture sessions, joins the backend worker thread). This is the primary lifecycle shape; explicit.close()exists for non-withusers. - Exceptions: a
MediawayErrorbase carrying the raw status code, with subclasses for the expected outcomes (EncoderUnavailableError,DeviceUnavailableError,CaptureUnsupportedError) so examples can catch-and-continue rather than crash on missing hardware. No status-code checking in example bodies. - Typestate as two classes (mirrors C++):
Muxer(Open:add_video_track/add_audio_track) →.begin()returnsLiveMuxer(push_packet / flush / poll_bytes). Calling track registration on aLiveMuxeris impossible, matching the ABI'sINVALID_STATE. - bytes for byte buffers:
poll_bytes() -> bytes;push_bytes(bytes);packet.payload -> bytes;frame.data -> bytes(NV12/BGRA8). The wrapper copies out of borrowed/owned native buffers — nomemoryviewleaking into the API. Rational(num, den)as a smalldataclass(frozen=True); info structs as dataclasses.EncodeSession(encoder)takes ownership of the encoder object;finish() -> bytesis terminal (noclose()after it).
Example scenarios
examples/ mirrors the Rust examples/ layout — sector subfolders, one file per
scenario (English comments only; each file's header comment states real vs.
aspirational):
| File | Capability | Real today? |
|---|---|---|
container/mux_roundtrip.py |
mux 90 fake video + audio packets → fMP4 → demux back, count packets | ✅ run verified |
pipeline/encode_to_mp4.py |
auto H.264 encode of 90 synthetic NV12 frames → out.mp4 |
✅ run verified |
pipeline/encode_audio.py |
auto AAC encode of 96 synthetic F32 stereo frames → audio-only fMP4 (ABI v2) | ✅ run verified (96 packets → 27372 bytes fMP4) |
device/camera_record.py |
camera + mic → H.264 + AAC → ONE two-track MP4 (remuxed; audio track registered with the encoder's AudioSpecificConfig) | ✅ run verified on real hardware (47 frames + 80 AAC packets → ~251 KB two-track MP4); video-only fallback without mic/audio backend |
device/capture_microphone.py |
microphone capture, raw PCM | ✅ run verified (real mic) |
pipeline/screen_record.py |
screen + mic → encode → MP4 | 🚧 aspirational — VideoCapture.open(source="screen") raises CaptureUnsupportedError today |
device/capture_screen.py |
screen capture only | 🚧 same gap, capture-only |
Rules
- English comments only.
- Map existing Rust surfaces; do not invent capabilities the Rust side doesn't have.
- Wrap the ABI fully: no
ctypestypes or raw handles visible in examples. - Not part of the Cargo workspace; durable API changes require an ADR (ADR-0004).
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 mediaway-0.1.1.tar.gz.
File metadata
- Download URL: mediaway-0.1.1.tar.gz
- Upload date:
- Size: 3.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76b2d8898d62e19cfe1e19363e4ce0f4b3441bac53779ae6cdf97c7def8db805
|
|
| MD5 |
ce1835bee8ff08816e6355623154744b
|
|
| BLAKE2b-256 |
38d67cc864152e62640190bf11d94458336bf09b014fe7b6effd377ab25ba88d
|
Provenance
The following attestation bundles were made for mediaway-0.1.1.tar.gz:
Publisher:
release.yml on nyxways/mediaway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mediaway-0.1.1.tar.gz -
Subject digest:
76b2d8898d62e19cfe1e19363e4ce0f4b3441bac53779ae6cdf97c7def8db805 - Sigstore transparency entry: 2335636684
- Sigstore integration time:
-
Permalink:
nyxways/mediaway@3ed32f2113c001c72c7266cf4713f48bc6dfdb20 -
Branch / Tag:
refs/heads/release/v0.1.1 - Owner: https://github.com/nyxways
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3ed32f2113c001c72c7266cf4713f48bc6dfdb20 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mediaway-0.1.1-py3-none-win_amd64.whl.
File metadata
- Download URL: mediaway-0.1.1-py3-none-win_amd64.whl
- Upload date:
- Size: 3.9 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8616cc7101ecacc030f844249c50cee631912615751cb9d15464575f9e787b74
|
|
| MD5 |
03147e70fb7fe41cf38b36d60ae08c58
|
|
| BLAKE2b-256 |
3f5ac89aedb6e49c60cd506783299b65916449ef457e04194deeabbe337f206c
|
Provenance
The following attestation bundles were made for mediaway-0.1.1-py3-none-win_amd64.whl:
Publisher:
release.yml on nyxways/mediaway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mediaway-0.1.1-py3-none-win_amd64.whl -
Subject digest:
8616cc7101ecacc030f844249c50cee631912615751cb9d15464575f9e787b74 - Sigstore transparency entry: 2335636698
- Sigstore integration time:
-
Permalink:
nyxways/mediaway@3ed32f2113c001c72c7266cf4713f48bc6dfdb20 -
Branch / Tag:
refs/heads/release/v0.1.1 - Owner: https://github.com/nyxways
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3ed32f2113c001c72c7266cf4713f48bc6dfdb20 -
Trigger Event:
push
-
Statement type: