Decentralized P2P live streaming — AES-256-GCM, LZ4, STUN/UPnP NAT traversal
Project description
p2p-stream v2
Decentralized, serverless P2P live streaming SDK. AES-256-GCM encrypted · LZ4 compressed · STUN/UPnP/HolePunch NAT traversal · Kademlia DHT · WebRTC mesh
Features
- C++ Core: Frame encryption (AES-256-GCM via OpenSSL) and compression (LZ4), compiled as a native Python extension via pybind11. Falls back to pure-Python when not built.
- NAT Traversal: Automatic STUN public-endpoint discovery, UPnP IGD port forwarding, and concurrent UDP hole punching — peers behind NAT routers connect directly with no relay.
- Kademlia DHT: Serverless peer discovery and out-of-band signaling. No central server required.
- WebRTC Mesh: aiortc-based direct peer connections with DTLS-SRTP transport security and proximity-based peer selection.
- 5-Line API:
StreamSessionpublishes or watches in under 5 lines of Python.
System Requirements
- Python >= 3.9
- C++17 compiler (GCC >= 10, Clang >= 12, MSVC 2019+)
- CMake >= 3.16
- OpenSSL >= 1.1
- Optional: liblz4 (LZ4 compression), libminiupnpc (UPnP port mapping)
Install
From source (builds native C++ extension)
pip install pybind11 cmake
pip install -e .
With all optional native deps (Ubuntu/Debian)
sudo apt install libssl-dev liblz4-dev libminiupnpc-dev
pip install pybind11 cmake
pip install -e .
Pure-Python fallback (no native build required)
pip install -r requirements.txt
All P2P streaming, DHT, and STUN features work. AES-256-GCM frame encryption and LZ4 compression require the native build.
Quick Start
Publisher (5 lines)
import asyncio, p2p_stream
async def main():
s = p2p_stream.StreamSession("myroom")
await s.publish(bootstrap=[("seed.example.com", 8468)])
await asyncio.Event().wait()
asyncio.run(main())
Watcher (5 lines)
import asyncio, p2p_stream
async def main():
s = p2p_stream.StreamSession("myroom")
await s.watch(bootstrap=[("seed.example.com", 8468)])
await p2p_stream.display_track(s.node.upstream_track)
asyncio.run(main())
E2E Encrypted Stream (requires native build)
from _p2pstream_core import FrameCodec
key = FrameCodec.generate_key()
publisher = p2p_stream.StreamSession("secure-room", key=key)
await publisher.publish(bootstrap=[("seed.example.com", 8468)])
watcher = p2p_stream.StreamSession("secure-room", key=key)
await watcher.watch(bootstrap=[("seed.example.com", 8468)])
CLI
p2p-stream genkey
export P2P_KEY=$(p2p-stream genkey)
p2p-stream publish --room live --host 0.0.0.0 --port 8468
p2p-stream watch --room live --bootstrap 192.168.1.10:8468 --port 8469
p2p-stream watch --room live --bootstrap node1:8468,node2:8469 --port 8470
Architecture
Publisher ──[DHT announce]──► KademliaDHT
│
Watcher ──[DHT lookup]───────────►│
◄──[nearest peer]─────────┘
──[request + public EP]──► Publisher
◄──[WebRTC offer]──────────┘
──[WebRTC answer]─────────► Publisher
◄═══[video stream]═══════════╝ (DTLS-SRTP)
C++ DataChannel path (when key= provided):
capture → LZ4 → AES-256-GCM → packetize(MTU=1200) → DataChannel
DataChannel → reassemble → AES-256-GCM decrypt → LZ4 decompress → display
NAT Traversal Strategy
- STUN — Query public (IP, port) via multiple Google/Cloudflare servers, pure-Python fallback included
- UPnP IGD — Request port mapping from router via libminiupnpc (silently skipped if unavailable)
- UDP Hole Punching — Concurrent 12-attempt 200ms-interval punching before WebRTC SDP exchange
- TURN — Add TURN credentials to
_ICEinnode.pyfor symmetric NAT environments
License
MIT
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 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 p2p_stream_v2_yoyo-2.0.0.tar.gz.
File metadata
- Download URL: p2p_stream_v2_yoyo-2.0.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8092f6fa1f20d62f27e82983380213d79d5a7c1d0bd28ac87c64281969c3f02e
|
|
| MD5 |
a0cdff4ace1980fca32bad2caf663ddf
|
|
| BLAKE2b-256 |
309d11711ddaef2e23361e6db02ea37a50c010310c5bdd3a9be0dc65947f156a
|
File details
Details for the file p2p_stream_v2_yoyo-2.0.0-py3-none-any.whl.
File metadata
- Download URL: p2p_stream_v2_yoyo-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03a93474f8865c5e567a2456ff7aedde309c7f55851088fba5f4b73a23ca9b3d
|
|
| MD5 |
a3324e0e60267170237d3d0b6596aedd
|
|
| BLAKE2b-256 |
4845df2ba2fbfcea998d5400f27687cc9c19723edac30dcc08f42541ccfdbff7
|