python-bedrock
Async Python reimplementation of the Bedrock (Minecraft) network protocol.
This project provides an asyncio-based library that mirrors the structure and basic API of the original JavaScript bedrock-protocol prototype. It aims to offer lightweight building blocks for creating Bedrock-compatible clients and servers, packet datatypes, and transforms (serialization/encryption).
Key features
- Async client and server primitives (
createClient,createServer) matching an evented API - Connection and packet helpers in
python_bedrock.connectionandpython_bedrock.transforms - Packet datatypes and (de)serialization utilities under
python_bedrock.datatypes - Example scripts in the
examples/folder and unit tests intests/
Requirements
- Python 3.9+
- Dependencies declared in
pyproject.toml:aiohttp,pyjwt,cryptography
Installation
Install from source in editable mode for development:
python -m pip install -e .
Or build a wheel and install (poetry/build-system is configured via pyproject.toml):
python -m build
python -m pip install dist/python_bedrock-*.whl
Quickstart
Basic client (connects to a Bedrock server and starts the reader loop):
import asyncio
from python_bedrock import createClient
async def main():
client = await createClient('127.0.0.1', 19132)
# Register handlers
client.on('packet', lambda pkt: print('raw packet', pkt))
client.on('text', lambda message, source: print(f'{source}: {message}'))
# Keep running until disconnected
try:
await asyncio.sleep(3600)
finally:
await client.disconnect()
asyncio.run(main())
Basic server:
import asyncio
from python_bedrock import createServer
async def run_server():
srv = createServer('0.0.0.0', 19132)
# Register events
srv.on('listening', lambda info: print('listening on', info))
srv.on('connect', lambda client: print('client connected', client))
# Start listening
await srv.listen()
try:
await asyncio.Event().wait() # run forever
finally:
await srv.close()
asyncio.run(run_server())
API overview
python_bedrock.createClient(host, port, **options)— asynchronous helper that opens a TCP connection, returns a startedClientinstance. The returnedClientimplements an evented API (on,off,_emit) and packet helpers such asqueue(packetId, payload)andsendMessage(message).python_bedrock.createServer(host, port, **options)— returns aServerinstance. Callawait server.listen()to start listening. TheServeremits events such aslistening,connect,disconnect, anderror. Useserver.broadcast(packetName, payload)to send packets to all clients.python_bedrock.Connection— low-level connection wrapper used internally; exposessend,receiveandclose.python_bedrock.datatypes— packet classes withserialize()anddeserialize()helpers. Seetests/test_packets.pyfor examples of packet construction and roundtrip assertions.
Examples and tests
- Examples are available in the
examples/directory (simple_client.py,simple_server.py, etc.). They are minimal stubs demonstrating API usage. - Unit tests use
pytest. Run the test suite with:
python -m pytest -q
Contributing
Contributions are welcome. For small changes, open a pull request with a clear description. Please:
- Run and update tests where appropriate
- Keep API changes backwards compatible when possible
- Follow existing code style and type hints
Notes and limitations
- This library is an independent reimplementation and does not provide complete feature parity with the original JS project. It focuses on core packet types and a small, evented runtime useful for experimentation and integration tests.
- Some example scripts are intentionally minimal and do not perform full protocol handshakes. See
python_bedrock/handshakeandpython_bedrock/authfor more advanced pieces.
License
MIT — see the LICENSE file for details.
Acknowledgements
This project mirrors ideas from the JavaScript bedrock-protocol project. See the parent repository for protocol-level documentation and packet specifications.
Metadata
Release files for python-bedrock 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_bedrock-1.1.1.tar.gz | 54.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_bedrock-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 124.7 kB
Release files / python_bedrock-1.1.1.tar.gz
| Download URL | python_bedrock-1.1.1.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04df58991a3997a3bddf0d15807656b3d1d2e4816bd16cd61dfb0ce3b66d34e1
|
|
BLAKE2b-256 checksum How to use checksums |
541131f348301e548bbbb01d48fe9c0f7823fc486c0b6110a14d9fdbf6f04e0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / python_bedrock-1.1.1-py3-none-any.whl
| Download URL | python_bedrock-1.1.1-py3-none-any.whl |
|---|---|
| Size | 69.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
384544ffd35f92cce528907cb7188329b8feee2237797009f0487f8f2630b842
|
|
BLAKE2b-256 checksum How to use checksums |
5dc48094b62ca154a6e003e0bfbc6fd3da2e8ab58d9ea2a18963469fc179bea2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|