Skip to main content

An async Python client for interacting with Minecraft servers via WebSocket API

Project description

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

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

mcwebapi-0.4.0.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

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

mcwebapi-0.4.0-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

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

Hashes for mcwebapi-0.4.0.tar.gz
Algorithm Hash digest
SHA256 15e8867921297ecf01eb5caf00733b6773b6ecf889414ee9417f569fc0a2cd54
MD5 172958fe276c68211bf495bfe02b2ba0
BLAKE2b-256 ac0ef84988589e4dd9255cd693e2f596465501c5b447df9a0212a6831f7645bf

See more details on using hashes here.

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

Hashes for mcwebapi-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b66f096afd1f659a3f010f84ecb7f2ea9784e9b2475a08cf9379dd18e2150fd9
MD5 0006b159ba581647df38b2343bd6d36f
BLAKE2b-256 7e750408b769b0cca0f084033e290ec166191067b8293cb2e4b6c2db80dd882c

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