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
Release files for mcwebapi 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mcwebapi-0.4.0.tar.gz | 40.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcwebapi-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.4 kB
Release files / mcwebapi-0.4.0.tar.gz
| Download URL | mcwebapi-0.4.0.tar.gz |
|---|---|
| Size | 40.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
15e8867921297ecf01eb5caf00733b6773b6ecf889414ee9417f569fc0a2cd54
|
|
BLAKE2b-256 checksum How to use checksums |
ac0ef84988589e4dd9255cd693e2f596465501c5b447df9a0212a6831f7645bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / mcwebapi-0.4.0-py3-none-any.whl
| Download URL | mcwebapi-0.4.0-py3-none-any.whl |
|---|---|
| Size | 52.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b66f096afd1f659a3f010f84ecb7f2ea9784e9b2475a08cf9379dd18e2150fd9
|
|
BLAKE2b-256 checksum How to use checksums |
7e750408b769b0cca0f084033e290ec166191067b8293cb2e4b6c2db80dd882c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|