Skip to main content

Python library for working with the mcsrvstat.us API - a service for checking the status of Minecraft servers

Project description

mcsrvstatus

supported python versions current PyPI version

A Python library for interacting with the mcsrvstat.us API to check Minecraft server status.

Features

  • Check Java and Bedrock Minecraft server status
  • Get player count, server version, and MOTD
  • Retrieve server icons
  • Both synchronous and asynchronous support
  • Simple and intuitive API
  • Comprehensive error handling

Installation

pip install mcsrvstatus

Quick Start

Synchronous Usage

from mcsrvstatus import MinecraftServerStatus

client = MinecraftServerStatus()

# Check if server is online
is_online = client.is_server_online("mc.hypixel.net")
print(f"Server online: {is_online}")

# Get full server status
status = client.get_server_status("mc.hypixel.net")
print(f"Players: {status['players']['online']}/{status['players']['max']}")

client.close()

Asynchronous Usage

import asyncio
from mcsrvstatus import AsyncMinecraftServerStatus

async def main():
    async with AsyncMinecraftServerStatus() as client:
        is_online = await client.is_server_online("mc.hypixel.net")
        print(f"Server online: {is_online}")
        
        status = await client.get_server_status("mc.hypixel.net")
        print(f"Players: {status['players']['online']}/{status['players']['max']}")

asyncio.run(main())

API Reference

MinecraftServerStatus (Sync)

Methods

get_server_status(server_address: str, version: int = 3) -> Dict[str, Any]

Get full server status information.

status = client.get_server_status("play.example.com")
print(status)
# {
#   "online": True,
#   "ip": "192.168.1.1",
#   "port": 25565,
#   "players": {"online": 50, "max": 100, "list": ["player1", "player2"]},
#   "version": "1.20.1",
#   "motd": {"clean": ["Welcome to our server!"]},
#   "icon": "data:image/png;base64,..."
# }

get_bedrock_status(server_address: str, version: int = 3) -> Dict[str, Any]

Get Bedrock server status.

status = client.get_bedrock_status("play.example.com")

is_server_online(server_address: str) -> bool

Check if server is online.

online = client.is_server_online("play.example.com")

get_player_count(server_address: str) -> Tuple[int, int]

Get current and maximum player count.

online_players, max_players = client.get_player_count("play.example.com")

get_server_version(server_address: str) -> Optional[str]

Get server version.

version = client.get_server_version("play.example.com")

get_server_motd(server_address: str) -> Optional[str]

Get server message of the day.

motd = client.get_server_motd("play.example.com")

get_player_list(server_address: str) -> List[str]

Get list of online players (if available).

players = client.get_player_list("play.example.com")

get_server_icon(server_address: str) -> Optional[str]

Get server icon as base64 string.

icon = client.get_server_icon("play.example.com")

AsyncMinecraftServerStatus (Async)

All methods are the same as the sync version but with async/await:

async with AsyncMinecraftServerStatus() as client:
    status = await client.get_server_status("play.example.com")
    online = await client.is_server_online("play.example.com")
    players = await client.get_player_count("play.example.com")

Error Handling

The library raises specific exceptions for different error cases:

from mcsrvstatus.exceptions import ServerNotFoundError, APIError, ConnectionError

try:
    status = client.get_server_status("nonexistent.server.com")
except ServerNotFoundError:
    print("Server is offline or doesn't exist")
except APIError as e:
    print(f"API error: {e}")
except ConnectionError as e:
    print(f"Network error: {e}")

Examples

Basic Server Information

from mcsrvstatus import MinecraftServerStatus

client = MinecraftServerStatus()

server = "mc.hypixel.net"

try:
    # Basic info
    print(f"Checking {server}...")
    
    if client.is_server_online(server):
        online, max_players = client.get_player_count(server)
        version = client.get_server_version(server)
        motd = client.get_server_motd(server)
        
        print(f"✓ Online: {online}/{max_players} players")
        print(f"✓ Version: {version}")
        print(f"✓ MOTD: {motd}")
    else:
        print("✗ Server is offline")

finally:
    client.close()

Multiple Servers Check

import asyncio
from mcsrvstatus import AsyncMinecraftServerStatus

async def check_servers():
    servers = [
        "mc.hypixel.net",
        "play.mineplex.com", 
        "hub.mcs.gg"
    ]
    
    async with AsyncMinecraftServerStatus() as client:
        tasks = []
        for server in servers:
            task = asyncio.create_task(check_single_server(client, server))
            tasks.append(task)
        
        await asyncio.gather(*tasks)

async def check_single_server(client, server):
    try:
        if await client.is_server_online(server):
            online, max_players = await client.get_player_count(server)
            print(f"{server}: {online}/{max_players} players")
        else:
            print(f"{server}: Offline")
    except Exception as e:
        print(f"{server}: Error - {e}")

asyncio.run(check_servers())

Bedrock Server

from mcsrvstatus import MinecraftServerStatus

client = MinecraftServerStatus()

try:
    status = client.get_bedrock_status("play.nethergames.org")
    print(f"Bedrock server online: {status['online']}")
    print(f"Players: {status['players']['online']}/{status['players']['max']}")
except Exception as e:
    print(f"Error: {e}")
finally:
    client.close()

Context Manager Usage

from mcsrvstatus import MinecraftServerStatus

# Automatically handles connection cleanup
with MinecraftServerStatus() as client:
    status = client.get_server_status("play.example.com")
    print(f"Server: {status['ip']}:{status['port']}")

API Versions

The mcsrvstat.us API supports versions 1, 2, and 3 (default). You can specify the version:

# Use API version 2
status = client.get_server_status("play.example.com", version=2)

Requirements

  • Python 3.6+
  • requests (for sync client)
  • aiohttp (for async client)

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Run tests: python -m pytest
  5. Submit a pull request

Changelog

1.0.0

  • Initial release
  • Sync and async support
  • Complete API coverage
  • Comprehensive error handling

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

mcsrvstatus-1.0.3.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

mcsrvstatus-1.0.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file mcsrvstatus-1.0.3.tar.gz.

File metadata

  • Download URL: mcsrvstatus-1.0.3.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for mcsrvstatus-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0905b3f124b6d82d55053a6049d8d969b7f59f5b1504056dc7534cd8ede3ba64
MD5 22b5c4b42f9e3eece80bb7eec8c42794
BLAKE2b-256 e449ecf796b53db3200168a89cee7da2b4a6440584cc9160b90f5b1344f130f7

See more details on using hashes here.

File details

Details for the file mcsrvstatus-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: mcsrvstatus-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for mcsrvstatus-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f651be95c53b9ef737ecfcb89cfa2db4022c3a54e02ffbad0c79e4dcc62887eb
MD5 9cf386d5ed2ef743be67de0cff4962ae
BLAKE2b-256 ec85a7d0842b4ccc1503e6790b4c4b60865d66af038a667b406747eafaf80dfa

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