Skip to main content

Python library for ActionNet P2P networking

Project description

PyActionNet

Python library for ActionNet P2P networking.

Connects to the same WebSocket tracker as ActionNetJS and establishes a WebRTC data channel for peer-to-peer communication.

Zero server setup. Just Python talking to JavaScript over WebRTC through public trackers.

Installation

pip install pyactionnet

Or install dependencies manually:

pip install aiortc websockets

Quick Start

from pyactionnet import ActionNetTrackerClient
import asyncio
import hashlib

app_id = "my-app-1"
infohash = hashlib.sha1(app_id.encode()).hexdigest()
peer_id = "user_123"

tracker = ActionNetTrackerClient(infohash=infohash, peer_id=peer_id)

@tracker.on("connection")
def on_connection(connection):
    print(f"Connected to {connection.remote_peer_id}")
    connection.send({"hello": "world"})

@tracker.on("data")
def on_data(data):
    print(f"Got: {data}")

async def main():
    await tracker.connect()

asyncio.run(main())

Architecture

The library has 3 classes (1:1 with JavaScript):

  • DataConnection - Low-level WebRTC data channel
  • ActionNetPeer - Wraps DataConnection with event handling
  • ActionNetTrackerClient - Connects to tracker, discovers peers

PyActionNet connects to public WebSocket trackers:

  • wss://tracker.openwebtorrent.com/
  • wss://tracker.btorrent.xyz/
  • wss://tracker.fastcast.nz/

The flow:

  1. Connect to tracker via WebSocket, announce with WebRTC offer
  2. Tracker relays offer to other peers
  3. Peer responds with WebRTC answer through tracker
  4. Direct P2P data channel established — data flows peer-to-peer

Tracker only handles WebRTC signaling. No server needed.

Example

Run the test example to verify browser↔Python P2P:

python examples/test_link.py

Open demo.html from ActionNetJS in your browser, join with app ID app-id-00000, and the Python client will find it.

Testing

pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyactionnet-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pyactionnet-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyactionnet-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.1

File hashes

Hashes for pyactionnet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 04f74966ca39b17f61c3d55d1efb7f3c0c9cc627bb14643895e2344a09e38ac2
MD5 16de4b6873637cf7a43cb08f1964d0ce
BLAKE2b-256 ec08a3c7ee248d4786077ad432f8ac5ad22c9b4de3a61a03a6717c99f91f1d7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page