raknet
Python bindings for RakNet, the UDP networking library used by Minecraft Bedrock. It ships a faithful binding of RakNet's public API and a pythonic layer on top of it, with both a synchronous and an asyncio interface.
import raknet
with raknet.create_connection(("play.example.com", 19132), timeout=5) as conn:
conn.send(b"\xfe...") # a Bedrock game packet
print(conn.recv(timeout=5))
Installation
pip install raknet
Requires Python 3.12 or newer. Prebuilt abi3 wheels are published for Windows and Linux
(x86-64); a single wheel works across all supported Python versions.
The three layers
| Module | Interface | Use it for |
|---|---|---|
raknet |
synchronous | blocking servers and clients, threads |
raknet.asyncio |
asyncio | event-loop applications; mirrors the sync API with await |
raknet.raw |
faithful C++ binding | direct access to RakPeerInterface and every RakNet type |
The two high-level layers share one connection model: a Peer accepts and initiates
connections, and each Connection is a message pipe with send / recv. Anything the
high-level layer does not cover is reachable through peer.raw.
Quick start
Server
import raknet
def handle(connection):
for message in connection: # iterates until the peer disconnects
connection.send(message) # echo it back
with raknet.create_server(("0.0.0.0", 19132), max_connections=32) as server:
server.serve_forever(handle) # one thread per connection
Client
import raknet
with raknet.create_connection(("127.0.0.1", 19132), timeout=5) as conn:
conn.send(b"\xfehello")
reply = conn.recv(timeout=5)
asyncio
The asyncio layer is the same API with await in front; per-call timeouts are left to
asyncio.timeout().
import asyncio
import raknet.asyncio
async def handle(connection):
async for message in connection:
await connection.send(message)
async def main():
server = await raknet.asyncio.create_server(("0.0.0.0", 19132))
async with server:
await server.serve_forever(handle)
asyncio.run(main())
Server-list ping
pong = raknet.ping(("play.example.com", 19132), timeout=5)
print(pong.round_trip_time, pong.data)
More runnable programs are in examples/.
Messages
send and recv move bytes verbatim; there is no added framing. RakNet reads the first byte
of every packet as a message id and only delivers packets whose id is a user id
(>= 0x86, ID_USER_PACKET_ENUM). Lower ids are consumed as RakNet's own control traffic, so
each payload must begin with a user id. Minecraft Bedrock uses 0xFE. Reliability, priority
and the ordering channel are per-call:
conn.send(data, reliability=raknet.PacketReliability.RELIABLE_ORDERED,
priority=raknet.PacketPriority.HIGH_PRIORITY, channel=0)
Errors
Failures raise exceptions rather than returning sentinels. All inherit from RakNetError, and
the connection-lifecycle ones also inherit from the builtin ConnectionError.
| Exception | Raised when |
|---|---|
StartupError |
the peer could not bind its socket |
ConnectError |
a connection attempt was rejected (.reason carries the cause) |
ConnectionClosedOK |
the remote disconnected gracefully |
ConnectionClosedError |
the connection was lost without notice |
TimeoutError |
a timeout= elapsed (the builtin) |
Building from source
Building needs a C++17 compiler and Conan. The raknet recipe is hosted on
the endstone remote:
conan remote add endstone https://conan.cloudsmith.io/endstone/conan/
pip install .
The conan-py-build backend drives Conan and CMake,
so no separate conan install step is required.
Development
pip install -e .
pytest
License
BSD-3-Clause. See LICENSE.
RakNet is © Oculus VR and released under a BSD-style license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 raknet-0.4.0.tar.gz.
File metadata
- Download URL: raknet-0.4.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ecf4d7cd081dac194995b5f75a224474d06f9d05be983b54bfdfd25c1bdc1bc
|
|
| MD5 |
0dfa8f11e6b4e121e629a6a0d149d637
|
|
| BLAKE2b-256 |
7143675dbc16ca85ee6dcec04d60d365eba5fee5eebcbc56c82b474956aceb6d
|
Provenance
The following attestation bundles were made for raknet-0.4.0.tar.gz:
Publisher:
release.yml on EndstoneMC/raknet-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raknet-0.4.0.tar.gz -
Subject digest:
2ecf4d7cd081dac194995b5f75a224474d06f9d05be983b54bfdfd25c1bdc1bc - Sigstore transparency entry: 2257942540
- Sigstore integration time:
-
Permalink:
EndstoneMC/raknet-python@d6de0c0110fdc43662e7498160626bc536e38501 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/EndstoneMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d6de0c0110fdc43662e7498160626bc536e38501 -
Trigger Event:
push
-
Statement type:
File details
Details for the file raknet-0.4.0-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: raknet-0.4.0-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 184.1 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c545e6b5754097acbfd25a0955157c5dd9afe4209f14ddc5e29a0d73faeabd9
|
|
| MD5 |
1f2fa53aeaa08b1bd8f060b1ea01a5f2
|
|
| BLAKE2b-256 |
c2bd756b17e53ce5429fce07c2b0a8d2fe9eef2ba7ff7fd7fa138ce98c539970
|
Provenance
The following attestation bundles were made for raknet-0.4.0-cp312-abi3-win_amd64.whl:
Publisher:
release.yml on EndstoneMC/raknet-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raknet-0.4.0-cp312-abi3-win_amd64.whl -
Subject digest:
7c545e6b5754097acbfd25a0955157c5dd9afe4209f14ddc5e29a0d73faeabd9 - Sigstore transparency entry: 2257942820
- Sigstore integration time:
-
Permalink:
EndstoneMC/raknet-python@d6de0c0110fdc43662e7498160626bc536e38501 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/EndstoneMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d6de0c0110fdc43662e7498160626bc536e38501 -
Trigger Event:
push
-
Statement type:
File details
Details for the file raknet-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: raknet-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 264.1 kB
- Tags: CPython 3.12+, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c512df290bca352bfb569a17011ee7ce073d731c715c4553b4ebda1b87c7b1dd
|
|
| MD5 |
ab0623c885a2aa2ed789375f5e54c39d
|
|
| BLAKE2b-256 |
f5024891fb23765a1b7d1f6b1b380b561952a88ea5c79a5d9d9d936c9e136606
|
Provenance
The following attestation bundles were made for raknet-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
release.yml on EndstoneMC/raknet-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
raknet-0.4.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
c512df290bca352bfb569a17011ee7ce073d731c715c4553b4ebda1b87c7b1dd - Sigstore transparency entry: 2257942693
- Sigstore integration time:
-
Permalink:
EndstoneMC/raknet-python@d6de0c0110fdc43662e7498160626bc536e38501 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/EndstoneMC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d6de0c0110fdc43662e7498160626bc536e38501 -
Trigger Event:
push
-
Statement type: