Skip to main content

MCAPI.TR Python SDK

The official, typed and zero-dependency Python client for the MCAPI.TR Minecraft Server Status API.

It supports Minecraft Java, legacy Java and Bedrock servers, synchronous and asynchronous applications, discovery endpoints, generated banners, icons and embeddable widgets.

Installation

pip install mcapitr

For local development:

pip install -e .

Python 3.9 or newer is required. The package has no runtime dependencies.

Quick start

from mcapitr import MCAPIClient

with MCAPIClient() as client:
    status = client.server_status("mc.hypixel.net")

print(status["online"])
if status.get("players"):
    print(status["players"]["online"])

Bedrock and legacy Java queries use explicit flags:

bedrock = client.server_status("play.example.net:19132", bedrock=True)
legacy = client.server_status("old.example.net", legacy=True)

Async usage

The async client provides the same API without blocking the event loop:

import asyncio

from mcapitr import AsyncMCAPIClient


async def main() -> None:
    async with AsyncMCAPIClient() as client:
        status = await client.server_status("mc.hypixel.net")
        print(status["version"]["name"])


asyncio.run(main())

Discovery and platform statistics

with MCAPIClient() as client:
    first_page = client.trends(limit=20)
    statistics = client.stats()

    for server in first_page["data"]:
        print(server["address"], server["players_online"])

    if first_page["meta"].get("hasNext"):
        next_page = client.trends(
            limit=20,
            cursor=first_page["meta"]["nextCursor"],
        )

Java Query

Servers with enable-query=true can return software, plugins, the map and the full player list. query_port sets the Query UDP port when it differs from the game port (it turns Query on):

status = client.server_status("mc.example.net", query=True)
other = client.server_status("mc.example.net", query_port=25575)
print(status.get("software"), status.get("plugins"))
print(status.get("query_data", {}).get("map"))

Plain-text status

For uptime checks, overlays and bots that need one value instead of JSON:

with MCAPIClient() as client:
    state = client.simple_status("mc.hypixel.net")      # "online", "stale" or "offline"
    players = client.text_field("mc.hypixel.net", "players")  # "52184"
    ping = client.text_field("mc.hypixel.net", "ping")         # None if not reported

simple_status returns "offline" instead of raising. "stale" is the last successful answer, kept while an outage is not yet confirmed. text_field accepts the names in mcapitr.TEXT_FIELDS (online, players, max_players, version, protocol, motd, ping); for an offline server it raises ServerNotFoundError, except "online", which returns "false".

Forge mods

Java status responses include mods (mod IDs) and mod_details with versions when a Forge server advertises them:

status = client.server_status("modded.example.net")
for mod in status.get("mod_details", []):
    print(mod["id"], mod["version"])  # version is None for server-only mods

Media URLs and downloads

URL helpers do not perform a network request:

icon_url = client.server_icon_url("mc.hypixel.net", size=128, image_format="webp")
banner_url = client.server_banner_url("mc.hypixel.net", size="large")
# No template background; on light pages use a dark text colour in the banner.
clear_url = client.server_banner_url("mc.hypixel.net", style="panorama", transparent=True)
widget_url = client.widget_url("mc.hypixel.net", size="large", theme="dark")
motd_url = client.motd_banner_url("&aWelcome to &bMy Server!")

The matching download methods return bytes:

icon = client.server_icon("mc.hypixel.net", size=128)
with open("server-icon.png", "wb") as image_file:
    image_file.write(icon)

Errors

HTTP and connection failures use dedicated exceptions:

from mcapitr import MCAPIClient, RateLimitError, ServerNotFoundError

try:
    status = MCAPIClient().server_status("offline.example.net")
except ServerNotFoundError as error:
    print("Server is offline or unreachable:", error)
except RateLimitError as error:
    print("Retry after:", error.retry_after)

Available exception classes are MCAPIError, NetworkError, APIError, BadRequestError, ServerNotFoundError, RateLimitError and ResponseDecodeError.

Client options

client = MCAPIClient(
    base_url="https://mcapi.tr/api/v1",
    timeout=10.0,
    user_agent="my-discord-bot/1.0",
)

Development

python -m unittest discover -s tests -v
python -m compileall -q src

Changelog

0.2.0: simple_status() and text_field() for the plain-text endpoints, transparent and the panorama style for banner URLs, mod_details and the freshness fields in the ServerStatus type, query and query_port on server_status() with the QueryData type. Plain-text error bodies are used as exception messages.

0.1.0: First release.

License

MIT

Metadata

Release files for mcapitr 0.2.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 mcapitr 0.2.0
File Size Uploaded Provenance Actions
mcapitr-0.2.0.tar.gz 14.7 kB Without provenance Details for mcapitr-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcapitr 0.2.0
File Interpreter ABI Platform Actions
mcapitr-0.2.0-py3-none-any.whl Python 3 none any Details for mcapitr-0.2.0-py3-none-any.whl

Total release size: 26.1 kB

Release files / mcapitr-0.2.0.tar.gz

Download URL mcapitr-0.2.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7b411489280bfe4154c1a15629b12adebdbddd7b67dcfe51f6e09c09ed34146f
BLAKE2b-256 checksum
How to use checksums
cf2dfb447393e159d2633ac69487800baf0762b96bb39612795b859c3bf74a05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / mcapitr-0.2.0-py3-none-any.whl

Download URL mcapitr-0.2.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
363ecb77a4ed4f7239564970cf45d949e4bb32c75b97009f12203143d1f6fa23
BLAKE2b-256 checksum
How to use checksums
867925a239304ad0b25031fa7438ac1acf7fcb2a78577907c4db7c2e1479770d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for mcapitr 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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