An async Python client for interacting with Minecraft servers via WebSocket API
Project description
Features
- Clean Async API - Modern async/await syntax with asyncio
- Event System - Subscribe to game events with decorators (
@PlayerChatEvent,@PlayerJoinEvent, etc.) - Type-safe - Full typing support with .pyi stubs for better IDE autocomplete
- Comprehensive - Player, Level, Block, Server, Entity, and Scoreboard management
- Lightweight - Minimal dependencies (just
websockets) - Easy to Use - Intuitive object-oriented interface
Installation
pip install mcwebapi
Quick Start
import asyncio
from mcwebapi import MinecraftAPI
async def main():
async with MinecraftAPI() as api:
# Get server info
server = api.Server()
info = await server.getInfo()
print(f"Connected to {info['version']}")
# Give items to player
player = api.Player("Steve")
await player.giveItem("minecraft:diamond", 64)
await player.sendMessage("You received 64 diamonds!")
# Set time to day
level = api.Level("minecraft:overworld")
await level.setDayTime(6000)
if __name__ == "__main__":
asyncio.run(main())
Event System
Subscribe to Minecraft events using decorators:
from mcwebapi import MinecraftAPI
from mcwebapi.events import PlayerChatEvent, PlayerJoinEvent
@PlayerChatEvent
async def on_chat(event):
print(f"{event.player_name}: {event.message}")
@PlayerJoinEvent
async def on_join(event):
print(f"{event.player_name} joined!")
async def main():
async with MinecraftAPI() as api:
events = api.events()
await events.start()
try:
while True:
await asyncio.sleep(1) # Keep alive
except KeyboardInterrupt:
print("\nStopping...")
asyncio.run(main())
Available Events:
@PlayerJoinEvent- Player joins server@PlayerQuitEvent- Player leaves server@PlayerChatEvent- Player sends chat message@PlayerDeathEvent- Player dies@BlockBreakEvent- Block broken@BlockPlaceEvent- Block placed@EntitySpawnEvent- Entity spawns@EntityDeathEvent- Entity dies
Documentation
- Quick Start Guide - Get started quickly
- Player Operations - Health, inventory, effects, teleportation
- Block Operations - Place blocks, manage inventories
- Entity Management - Spawn and control entities
- Level Management - Time, weather, world settings
- Scoreboard - Objectives, teams, scores
- Server Management - Server info and administration
- Code Examples - Practical examples for common tasks
Server Setup
Requires the MinecraftWebsocketAPI mod on your Minecraft 1.21.1 server.
Basic Setup:
- Install the NeoForge mod
- Configure
config/mcwebapi-server.tomlwith your settings (port, auth key) - Restart the server
Python Client:
api = MinecraftAPI(
host="localhost",
port=8765,
auth_key="your-secret-key"
)
Requirements
- Python 3.8+
websockets>=12.0- Minecraft 1.21.1 server with MinecraftWebsocketAPI mod
Contributing
Contributions welcome! Please open an issue or PR on GitHub.
Links
- Documentation: Wiki
- PyPI: pypi.org/project/mcwebapi
- Server Mod: MinecraftWebsocketAPI
- Issues: GitHub Issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mcwebapi-0.4.0.tar.gz
(40.1 kB
view details)
Built Distribution
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
mcwebapi-0.4.0-py3-none-any.whl
(52.4 kB
view details)
File details
Details for the file mcwebapi-0.4.0.tar.gz.
File metadata
- Download URL: mcwebapi-0.4.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e8867921297ecf01eb5caf00733b6773b6ecf889414ee9417f569fc0a2cd54
|
|
| MD5 |
172958fe276c68211bf495bfe02b2ba0
|
|
| BLAKE2b-256 |
ac0ef84988589e4dd9255cd693e2f596465501c5b447df9a0212a6831f7645bf
|
File details
Details for the file mcwebapi-0.4.0-py3-none-any.whl.
File metadata
- Download URL: mcwebapi-0.4.0-py3-none-any.whl
- Upload date:
- Size: 52.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b66f096afd1f659a3f010f84ecb7f2ea9784e9b2475a08cf9379dd18e2150fd9
|
|
| MD5 |
0006b159ba581647df38b2343bd6d36f
|
|
| BLAKE2b-256 |
7e750408b769b0cca0f084033e290ec166191067b8293cb2e4b6c2db80dd882c
|