Skip to main content

Python client for ActionNet P2P multiplayer networking

Project description

PyActionNet

Python client for ActionNet P2P multiplayer networking.

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

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

Installation

pip install .

Or install dependencies manually:

pip install aiortc websockets

Quick Start

from pyactionnet import PyActionNet
import asyncio

client = PyActionNet("my-game-1", "Player1")

@client.on("connected")
def on_connected(peer_id):
    print(f"Connected to {peer_id}")

@client.on("message")
def on_message(data):
    print(f"Got: {data}")
    client.send({"reply": "hello"})

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

asyncio.run(main())

Events

  • connected(peer_id) - WebRTC data channel opened with peer
  • disconnected(peer_id) - Peer disconnected
  • message(data) - Received data from peer (dict or str)
  • peer_confirmed(data) - Handshake received (contains peerId, username, applicationId)

API

  • PyActionNet(app_id, username="Player") - Create a new client
  • client.on(event, callback) - Register event handler (also usable as decorator)
  • await client.connect(tracker_url=None) - Connect to tracker and wait for peer
  • await client.send(data) - Send data to connected peer (dict or str)
  • await client.disconnect() - Close all connections

Architecture

PyActionNet connects to the same public WebSocket trackers as ActionNetJS:

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

The flow:

  1. Python creates a WebRTC offer and connects to a tracker via WebSocket
  2. Tracker relays the offer to browser peers (ActionNetJS)
  3. Browser responds with a WebRTC answer through the tracker
  4. Direct P2P data channel is established — game data flows peer-to-peer

No server needed. No bridge. The tracker only handles WebRTC signaling.

Example

Run the example to test 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 Distribution

pyactionnet-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

pyactionnet-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pyactionnet-0.1.0.tar.gz.

File metadata

  • Download URL: pyactionnet-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.1

File hashes

Hashes for pyactionnet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fbcc661539395e92dd78285e036dbf80cd4b57e68654de2d9da1e44f5d2fc66b
MD5 da49e2c654d50a1bdf7f365d7d025c95
BLAKE2b-256 26b84b9ec566cbb704cf1d3f444acf110acc6cb5801415c59bdaf33f766a2079

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyactionnet-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88c245d668dd77c310801e9e15cf066a197e43ea4a6ad0b496bd9d5def7082dc
MD5 57a4a57e98b98ad2a7f64f4279cab2b7
BLAKE2b-256 4b9488b1702e721f52c8d6c776ebf686b848cc3e8916e85dc0f5627ed58a2ad1

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