Skip to main content
mcwebapi

Minecraft Websocket API

Async Python client library for the Minecraft WebSocket API mod

PyPI Python Downloads

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

📖 Full Documentation on Wiki

Server Setup

Requires the MinecraftWebsocketAPI mod on your Minecraft 1.21.1 server.

Basic Setup:

  1. Install the NeoForge mod
  2. Configure config/mcwebapi-server.toml with your settings (port, auth key)
  3. Restart the server

Python Client:

api = MinecraftAPI(
    host="localhost",
    port=8765,
    auth_key="your-secret-key"
)

Requirements

Contributing

Contributions welcome! Please open an issue or PR on GitHub.

Links

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)

Source distribution for mcwebapi 0.4.0
File Size Uploaded
mcwebapi-0.4.0.tar.gz 40.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcwebapi 0.4.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page