Metadata-Version: 2.4
Name: pyactionnet
Version: 0.2.0
Summary: Python library for ActionNet P2P networking
License-Expression: MIT
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: aiortc>=1.9.0
Requires-Dist: websockets>=13.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"

# PyActionNet

Python library for ActionNet P2P networking.

Connects to the same WebSocket tracker as [ActionNetJS](https://github.com/) 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

```bash
pip install pyactionnet
```

Or install dependencies manually:

```bash
pip install aiortc websockets
```

## Quick Start

```python
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:

```bash
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

```bash
pytest
```

## License

MIT
