Skip to main content

Async Python reimplementation of the Bedrock protocol.

Project description

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.connection and python_bedrock.transforms
  • Packet datatypes and (de)serialization utilities under python_bedrock.datatypes
  • Example scripts in the examples/ folder and unit tests in tests/

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 started Client instance. The returned Client implements an evented API (on, off, _emit) and packet helpers such as queue(packetId, payload) and sendMessage(message).
  • python_bedrock.createServer(host, port, **options) — returns a Server instance. Call await server.listen() to start listening. The Server emits events such as listening, connect, disconnect, and error. Use server.broadcast(packetName, payload) to send packets to all clients.
  • python_bedrock.Connection — low-level connection wrapper used internally; exposes send, receive and close.
  • python_bedrock.datatypes — packet classes with serialize() and deserialize() helpers. See tests/test_packets.py for 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/handshake and python_bedrock/auth for 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.

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

python_bedrock-1.1.1.tar.gz (54.9 kB view details)

Uploaded Source

Built Distribution

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

python_bedrock-1.1.1-py3-none-any.whl (69.8 kB view details)

Uploaded Python 3

File details

Details for the file python_bedrock-1.1.1.tar.gz.

File metadata

  • Download URL: python_bedrock-1.1.1.tar.gz
  • Upload date:
  • Size: 54.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for python_bedrock-1.1.1.tar.gz
Algorithm Hash digest
SHA256 04df58991a3997a3bddf0d15807656b3d1d2e4816bd16cd61dfb0ce3b66d34e1
MD5 9a6bb88f616c32f902d969e7dfec3484
BLAKE2b-256 541131f348301e548bbbb01d48fe9c0f7823fc486c0b6110a14d9fdbf6f04e0d

See more details on using hashes here.

File details

Details for the file python_bedrock-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: python_bedrock-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 69.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for python_bedrock-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 384544ffd35f92cce528907cb7188329b8feee2237797009f0487f8f2630b842
MD5 2b52f32279ad65d7bb6d972348c2f966
BLAKE2b-256 5dc48094b62ca154a6e003e0bfbc6fd3da2e8ab58d9ea2a18963469fc179bea2

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