python-bedrock


Namepython-bedrock JSON
Version 1.1.0 PyPI version JSON
download
home_pageNone
SummaryAsync Python reimplementation of the Bedrock protocol.
upload_time2025-10-22 21:21:51
maintainerNone
docs_urlNone
authorghulq
requires_python>=3.9
licenseMIT
keywords minecraft bedrock protocol async
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
python -m pip install -e .
```

Or build a wheel and install (poetry/build-system is configured via `pyproject.toml`):

```bash
python -m build
python -m pip install dist/python_bedrock-*.whl
```

Quickstart

Basic client (connects to a Bedrock server and starts the reader loop):

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

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

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


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-bedrock",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "minecraft, bedrock, protocol, async",
    "author": "ghulq",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5f/b0/f21cca7c5f6167efa940def1db27b68bcb82b2840f4b79daeced70f3eb6e/python_bedrock-1.1.0.tar.gz",
    "platform": null,
    "description": "# python-bedrock\n\nAsync Python reimplementation of the Bedrock (Minecraft) network protocol.\n\nThis 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).\n\nKey features\n- Async client and server primitives (`createClient`, `createServer`) matching an evented API\n- Connection and packet helpers in `python_bedrock.connection` and `python_bedrock.transforms`\n- Packet datatypes and (de)serialization utilities under `python_bedrock.datatypes`\n- Example scripts in the `examples/` folder and unit tests in `tests/`\n\nRequirements\n- Python 3.9+\n- Dependencies declared in `pyproject.toml`: `aiohttp`, `pyjwt`, `cryptography`\n\nInstallation\n\nInstall from source in editable mode for development:\n\n```bash\npython -m pip install -e .\n```\n\nOr build a wheel and install (poetry/build-system is configured via `pyproject.toml`):\n\n```bash\npython -m build\npython -m pip install dist/python_bedrock-*.whl\n```\n\nQuickstart\n\nBasic client (connects to a Bedrock server and starts the reader loop):\n\n```python\nimport asyncio\nfrom python_bedrock import createClient\n\nasync def main():\n\tclient = await createClient('127.0.0.1', 19132)\n\n\t# Register handlers\n\tclient.on('packet', lambda pkt: print('raw packet', pkt))\n\tclient.on('text', lambda message, source: print(f'{source}: {message}'))\n\n\t# Keep running until disconnected\n\ttry:\n\t\tawait asyncio.sleep(3600)\n\tfinally:\n\t\tawait client.disconnect()\n\nasyncio.run(main())\n```\n\nBasic server:\n\n```python\nimport asyncio\nfrom python_bedrock import createServer\n\nasync def run_server():\n\tsrv = createServer('0.0.0.0', 19132)\n\n\t# Register events\n\tsrv.on('listening', lambda info: print('listening on', info))\n\tsrv.on('connect', lambda client: print('client connected', client))\n\n\t# Start listening\n\tawait srv.listen()\n\n\ttry:\n\t\tawait asyncio.Event().wait()  # run forever\n\tfinally:\n\t\tawait srv.close()\n\nasyncio.run(run_server())\n```\n\nAPI overview\n\n- `python_bedrock.createClient(host, port, **options)` \u2014 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)`.\n- `python_bedrock.createServer(host, port, **options)` \u2014 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.\n- `python_bedrock.Connection` \u2014 low-level connection wrapper used internally; exposes `send`, `receive` and `close`.\n- `python_bedrock.datatypes` \u2014 packet classes with `serialize()` and `deserialize()` helpers. See `tests/test_packets.py` for examples of packet construction and roundtrip assertions.\n\nExamples and tests\n\n- Examples are available in the `examples/` directory (`simple_client.py`, `simple_server.py`, etc.). They are minimal stubs demonstrating API usage.\n- Unit tests use `pytest`. Run the test suite with:\n\n```bash\npython -m pytest -q\n```\n\nContributing\n\nContributions are welcome. For small changes, open a pull request with a clear description. Please:\n\n- Run and update tests where appropriate\n- Keep API changes backwards compatible when possible\n- Follow existing code style and type hints\n\nNotes and limitations\n\n- 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.\n- 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.\n\nLicense\n\nMIT \u2014 see the `LICENSE` file for details.\n\nAcknowledgements\n\nThis project mirrors ideas from the JavaScript `bedrock-protocol` project. See the parent repository for protocol-level documentation and packet specifications.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Async Python reimplementation of the Bedrock protocol.",
    "version": "1.1.0",
    "project_urls": null,
    "split_keywords": [
        "minecraft",
        " bedrock",
        " protocol",
        " async"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cc67da2c26c2d9384bfc2226cf51143313067d22943e3bb0b9f2c2089b862807",
                "md5": "d200c4d400ea66d162d13bf0b30d4166",
                "sha256": "a58749acb76ac6f87df2c607c10adc347b4be9386649371ecf94229f49c61f9f"
            },
            "downloads": -1,
            "filename": "python_bedrock-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d200c4d400ea66d162d13bf0b30d4166",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 68135,
            "upload_time": "2025-10-22T21:21:47",
            "upload_time_iso_8601": "2025-10-22T21:21:47.425693Z",
            "url": "https://files.pythonhosted.org/packages/cc/67/da2c26c2d9384bfc2226cf51143313067d22943e3bb0b9f2c2089b862807/python_bedrock-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5fb0f21cca7c5f6167efa940def1db27b68bcb82b2840f4b79daeced70f3eb6e",
                "md5": "11a071b5b5b1bbcd4d66987205ef3e9c",
                "sha256": "20e42b2ea4124fcbe262fd30977bc2c27d0340a0f325091a524a787132aad627"
            },
            "downloads": -1,
            "filename": "python_bedrock-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "11a071b5b5b1bbcd4d66987205ef3e9c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 53233,
            "upload_time": "2025-10-22T21:21:51",
            "upload_time_iso_8601": "2025-10-22T21:21:51.260020Z",
            "url": "https://files.pythonhosted.org/packages/5f/b0/f21cca7c5f6167efa940def1db27b68bcb82b2840f4b79daeced70f3eb6e/python_bedrock-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-22 21:21:51",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "python-bedrock"
}
        
Elapsed time: 1.17477s