tstrans
Python bindings (via PyO3) for the ts-transformer Rust workspace.
Status:
tstranscovers file inspection + construction (Demuxer/Muxer/MuxerFileSink), typed KLV decode + encode for ST 0601 / ST 0102 / ST 0605 / ST 0903 (withVTargetPack), codec parsers for H.264 / H.265 / H.266 / AV1 / AAC / MPEG-2 audio, optional pandas DataFrame adapters + NumPy snapshot views viapip install tstrans[pandas], and live transports: the pipeline shells (tstrans.shells— Sender / Receiver / MuxSender / DemuxReceiver, opened from ansrt://,rtp://,udp://,tcp://orrist://URL), SRT (tstrans.srt— Builder / Socket / Listener + Managed* auto-reconnect + ReconnectPolicy), RTP + RTSP (tstrans.rtp— Transport / RecvTransport / RtspClient / RtspServer / MountHandle), raw UDP / TCP / RIST (tstrans.udp/tstrans.tcp/tstrans.rist), and HLS publishing (tstrans.hls). Minimum Python 3.11.
The wheels also include WebRTC (WHEP) playback to browsers
(tstrans.webrtc), and the typed metadata support covers ST 1204 Core ID
(CoreId), ST 0806 RVT (RvtLs), ST 1010 SDCC-FLP (SdccFlp) and the
ST 0805 KLV-to-CoT conversion helpers (CotConfig,
platform_position_xml, sensor_point_of_interest_xml). See the
Python guide
for their APIs.
Install
pip install tstrans
Optional extras for DataFrame / NumPy integration:
pip install 'tstrans[pandas]'
Quickstart
Inspect a .ts file:
from tstrans.io import parse_file, probe
from tstrans.mpegts import DemuxEvent
# Quick summary
r = probe("capture.ts")
print(r.video_codecs, r.audio_codecs, r.has_klv)
# Full event stream
for event in parse_file("capture.ts"):
match event:
case DemuxEvent.Video(pts=p, codec=c, raw=b):
print(f"Video {c.name} pts={p.ms}ms len={len(b)}")
case DemuxEvent.Metadata(pts=p, payload=b):
print(f"KLV pts={p.ms}ms len={len(b)}")
Build a .ts file (single-program H.264):
from tstrans.mpegts import (
Muxer,
MuxerConfigBuilder,
MuxerProgramConfigBuilder,
Pts90khz,
VideoCodec,
)
prog = (
MuxerProgramConfigBuilder(program_number=1, pmt_pid=0x100)
.add_video(0x101, VideoCodec.H264)
.build()
)
cfg = MuxerConfigBuilder().add_program(prog).build()
m = Muxer(cfg)
with m.write_file("out.ts") as proxy:
proxy.push_video(nal_bytes, pts=Pts90khz.from_raw(900_000), key_frame=True)
RTP + RTSP transport
tstrans.rtp ships RTP-over-UDP and a full RTSP client + server. Available
by default in published wheels — no extra needed (pip install tstrans
already includes it). The Rust-side rtp cargo feature is on by default;
source builds that don't need it can opt out with
maturin develop --no-default-features for a smaller binary.
Connect to a camera and iterate demuxed events:
from tstrans.rtp import RtspClient, RtspClientConfig
from tstrans.mpegts import DemuxEvent
cfg = RtspClientConfig(url="rtsp://camera.local/live")
with RtspClient.connect(cfg) as session:
demux = session.into_demux_receiver()
for event in demux:
if isinstance(event, DemuxEvent.Video):
handle(event.raw)
Publish a stream from your own RTSP server:
from tstrans.rtp import RtspServer, RtspServerConfig
from tstrans.mpegts import MuxerProgramConfigBuilder, Pts90khz, VideoCodec
program = (
MuxerProgramConfigBuilder(1, 0x100)
.add_video(0x101, VideoCodec.H264)
.build()
)
with RtspServer.start(RtspServerConfig(bind_addr="0.0.0.0:8554")) as server:
mount = server.add_unicast_mount("/live", program)
mount.push_video(nal_bytes, pts=Pts90khz.from_raw(0), key_frame=True)
The full surface — Transport / RecvTransport for raw RTP, the
tstrans.shells shells for one-call mux/demux, RtspClient /
RtspSession with Basic + Digest auth and TCP-interleaved fallback,
RtspServer + MountHandle with five push methods (each with a _to
multi-stream twin) and multicast mounts — is documented in the per-class
docstrings and the python/tstrans/rtp.pyi type stubs (checked against the
runtime by mypy.stubtest in CI).
SRT transport
tstrans.srt ships full SRT (Secure Reliable Transport) bindings on top
of libsrt 1.5.7 — classes spanning low-level Builder / Socket /
Listener primitives (the Sender / Receiver / MuxSender /
DemuxReceiver shells live in tstrans.shells), and
ManagedSender / ManagedReceiver / ManagedMuxSender /
ManagedDemuxReceiver for auto-reconnect-with-gap-buffer ergonomics.
Available by default in published wheels — no extra needed
(pip install tstrans already includes it). The Rust-side srt cargo
feature is on by default; source builds that don't need SRT can opt
out with maturin develop --no-default-features for a smaller binary
that drops the libsrt + mbedTLS link.
Hello world — caller-side send + listener-side receive:
import threading
from tstrans.shells import Receiver, Sender
# Listener side (run on one host / thread):
def listen_side() -> None:
with Receiver.open("srt://0.0.0.0:9000?mode=listener") as rx:
chunk = rx.recv_bytes(max_len=1500)
print(f"received {len(chunk)} bytes; sync byte = {chunk[0]:#04x}")
threading.Thread(target=listen_side, daemon=True).start()
# Caller side (the other host / thread):
with Sender.open("srt://127.0.0.1:9000?mode=caller") as tx:
payload = (b"\x47" + b"\x00" * 187) * 7 # one 1316-byte TS bundle
tx.send_bytes(payload)
Full mux + demux example — push H.264 NALs + KLV blobs from the caller,
iterate DemuxEvents on the listener:
import threading
from tstrans.shells import DemuxReceiver, MuxSender
from tstrans.mpegts import (
DemuxEvent, KlvStreamType, MuxerProgramConfigBuilder, Pts90khz, VideoCodec,
)
program = (
MuxerProgramConfigBuilder(program_number=1, pmt_pid=0x100)
.add_video(0x101, VideoCodec.H264)
.add_klv(0x102, KlvStreamType.SYNCHRONOUS_METADATA, carries_pts=True)
.build()
)
def consumer() -> None:
with DemuxReceiver.open("srt://:9001?mode=listener") as rx:
for event in rx:
if isinstance(event, DemuxEvent.Video):
print(f"video pts={event.pts.ms}ms nals={len(event.parse())}")
elif isinstance(event, DemuxEvent.Metadata):
print(f"klv pts={event.pts.ms}ms len={len(event.payload)}")
threading.Thread(target=consumer, daemon=True).start()
with MuxSender.open(
"srt://127.0.0.1:9001?mode=caller", program
) as tx:
# tx.send_video / tx.send_klv handle bundling, PSI emission, and
# ts-packet framing transparently.
tx.send_video(nal_bytes, pts=Pts90khz.from_raw(0), key_frame=True)
tx.send_klv(klv_ls_bytes, pts=Pts90khz.from_raw(0))
Builder + Socket promotion for fine-grained control (passphrase,
custom latency, stream id, congestion mode):
import tstrans.srt
# Caller side with encryption + a custom SRT latency.
sock = (
tstrans.srt.Builder("srt://127.0.0.1:9000?mode=caller")
.passphrase("hunter-too-long-thanks!!") # >= 10 chars
.latency_ms(200)
.stream_id("cam-01")
.caller()
.connect()
)
sender = sock.into_sender() # consumes the Socket
sender.send_bytes(b"...")
sender.close()
Auto-reconnect with ManagedReceiver — wraps the underlying SRT
transport in a tst_pipeline::ManagedRecvTransport that catches
connection breaks and re-binds + re-accepts per a ReconnectPolicy;
reconnect_attempts() counts the reconnects. (ManagedDemuxReceiver
also surfaces each reconnect as a DemuxEvent.ReconnectDiscontinuity.)
import tstrans.srt
from tstrans.srt import BackoffStrategy, ReconnectPolicy
policy = ReconnectPolicy(
max_attempts=5,
backoff=BackoffStrategy.exponential(base_ms=100, max_ms=10_000),
)
with tstrans.srt.ManagedReceiver.from_url(
"srt://:9000?mode=listener", policy=policy
) as rx:
while True:
try:
chunk = rx.recv_bytes(max_len=1500)
print(f"received {len(chunk)} bytes; "
f"reconnects so far = {rx.reconnect_attempts()}")
except KeyboardInterrupt:
break
The full surface — Builder / Socket /
Listener for low-level construction, tstrans.shells for the shells, ManagedSender /
ManagedReceiver / ManagedMuxSender / ManagedDemuxReceiver for
auto-reconnect, plus ReconnectPolicy / BackoffStrategy /
OverflowPolicy policy types and SrtStats — is documented in the per-class docstrings and the
python/tstrans/srt.pyi type stubs (checked against the runtime by
mypy.stubtest in CI).
See also
docs/languages/python.md is the full Python guide, including the DataFrame / NumPy integration.
Metadata
Release files for tstrans 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tstrans-0.10.0.tar.gz | 7.8 MB | With provenance | Details for tstrans-0.10.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| tstrans-0.10.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for tstrans-0.10.0-cp311-abi3-win_amd64.whl |
| tstrans-0.10.0-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details for tstrans-0.10.0-cp311-abi3-manylinux_2_28_x86_64.whl |
| tstrans-0.10.0-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details for tstrans-0.10.0-cp311-abi3-manylinux_2_28_aarch64.whl |
| tstrans-0.10.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for tstrans-0.10.0-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 35.0 MB
Release files / tstrans-0.10.0.tar.gz
| Download URL | tstrans-0.10.0.tar.gz |
|---|---|
| Size | 7.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb5c8ca94f42655c088396180b633355987f547daa8311aab24d0568b7bb2a1a
|
|
BLAKE2b-256 checksum How to use checksums |
d44dbecd0c6d81ba61f1128137bb88ccea093166882b3ea332416acfd9ce01dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / tstrans-0.10.0-cp311-abi3-win_amd64.whl
| Download URL | tstrans-0.10.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 6.9 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e6c56b31f0c8f9de47c32352ae295a4f4e1108966e6d9d535873162c4fc84e6a
|
|
BLAKE2b-256 checksum How to use checksums |
e4a3e0d1af33a39afaec84d923a1aee67847c47da9949cce4aaaf7835e6d3c80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / tstrans-0.10.0-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | tstrans-0.10.0-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f9e7af95650e52fa82b8d5a5e9c02caa265e7435b009fd4cd5b01149170c03bb
|
|
BLAKE2b-256 checksum How to use checksums |
18ceb16374611fc174cd4fb72009a1987232b87d2d5b43ccc15272a0a3b44800
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / tstrans-0.10.0-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | tstrans-0.10.0-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 6.7 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
9ad0013f46fb95d77f3529ad83776302c2734020459ac07e4ada2038bf796bea
|
|
BLAKE2b-256 checksum How to use checksums |
28781bb7d2dd9ae9c93cda3b4f735d2a24f95f274b2b5cc3ac44d9a4b3feebd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / tstrans-0.10.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | tstrans-0.10.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 6.3 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7258fe4e4dfd4f9b2b2c8f736001b95506cea23bfbd088207edbde01654f3294
|
|
BLAKE2b-256 checksum How to use checksums |
c842f5e2ee9edf93e395886676714fa8c3a4a98275c1330cfdbd8963079ef2ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for tstrans 0.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for tstrans-0.10.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.