Skip to main content

MythicMC Public API (Python)

Python client for the MythicMC Public API. Python 3.10 or newer, synchronous and asynchronous, built on httpx.

Create an API key in the developer portal with your MythicMC forum account. Production keys use development limits until approved.

Install

pip install mythicmc-sdk

Install from source

pip install "git+https://github.com/mythicmcnetwork/mythicmc-sdk.git#subdirectory=python"

Usage

import os
from mythicmc import MythicMC, NotFoundError

with MythicMC(os.environ["MYTHICMC_API_KEY"]) as api:
    player = api.get_player("Vicente_1313")  # username or UUID
    print(player.rank.label, "unknown" if player.online is None else player.online)
    print(player.meta.data_as_of)  # UTC cutoff this response reflects

    try:
        survival = api.get_player_stats("Vicente_1313").survival
        print(survival.combat.kills, survival.net_worth.total if survival.net_worth else "unpublished")
    except NotFoundError:
        print("no published Survival statistics")

    for row in api.get_leaderboard("kills", "weekly").rows:
        print(row.rank, row.name, row.value)

AsyncMythicMC has the same methods as coroutines, for Discord bots and other asyncio programs:

import asyncio
import os
from mythicmc import AsyncMythicMC

async def main() -> None:
    async with AsyncMythicMC(os.environ["MYTHICMC_API_KEY"]) as api:
        profile, team = await asyncio.gather(api.get_player("Vicente_1313"), api.get_player_team("Vicente_1313"))
    print(profile.rank.label, team.team.name if team.team else "no team")

asyncio.run(main())

Both clients hold an httpx connection pool. Use them as context managers, or call close() yourself — await api.close() on the asynchronous one.

Method Endpoint
get_player(id) GET /v1/players/{id}
get_player_stats(id) GET /v1/players/{id}/stats
get_player_progression(id) GET /v1/players/{id}/progression
get_player_team(id) GET /v1/players/{id}/team
get_player_crate_keys(id) GET /v1/players/{id}/crate-keys
list_leaderboards() GET /v1/leaderboards
get_leaderboard(type, period) GET /v1/leaderboards/{type}/{period}
health() GET /health

id is a username, case-insensitive, or a UUID with or without dashes.

The full API reference includes additional endpoints you can call directly over HTTP.

Replies are frozen dataclasses whose snake_case attributes come from the JSON's camelCase keys. Each reply also carries meta, parsed from the response headers, and raw, the decoded JSON body as a dict. Keys the models do not know about are ignored, so a field the API adds later reaches you through raw rather than breaking an older client.

Options

Argument Default
api_key required Positional; the rest are keyword-only.
base_url https://api.mythicmc.net
timeout 10.0 Seconds, per attempt.
max_retries 2 Retries after a 429, each waiting for Retry-After, or a second when there is none. A wait over a minute raises instead. 0 disables.
transport None An httpx transport, for tests or proxies.

Errors

Every response the client cannot turn into data raises a MythicMCError. status is the HTTP status; message is the API's error string, or a stand-in when the response carried none.

Class Status
BadRequestError 400 Not a valid username or UUID.
AuthenticationError 401 Missing or invalid key.
NotFoundError 404 Unknown player or board, or no published Survival statistics.
RateLimitError 429 Retries exhausted. retry_after is seconds, or None.
UnavailableError 503 Not published yet, an ambiguous username, or a server fault. Retrying later can work.

Any other status, and a 2xx whose body is not the shape the model declares, raises MythicMCError itself. Network failures and timeouts raise httpx's own exceptions.

Examples

examples holds one file per group of endpoints, plus async_lookup.py for AsyncMythicMC.

pip install .
MYTHICMC_API_KEY=mmc_... python examples/get_player.py Vicente_1313

Set MYTHICMC_API_URL to run them against a mock server instead of the live API.

Development

pip install -e .
python -m unittest discover -s tests

Release files for mythicmc-sdk 0.1.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 mythicmc-sdk 0.1.0
File Size Uploaded
mythicmc_sdk-0.1.0.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mythicmc-sdk 0.1.0
File Interpreter ABI Platform
mythicmc_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.8 kB

Release files / mythicmc_sdk-0.1.0.tar.gz

Download URL mythicmc_sdk-0.1.0.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d0ea49a49ca14a6962bd396a2ff269f74c3d8f3f1e33f6f44f74724fb9b89c92
BLAKE2b-256 checksum
How to use checksums
52389ee2b0582f102c9e0803b74d59db856b22c38c42bff83e04c3a8b7f2f491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release files / mythicmc_sdk-0.1.0-py3-none-any.whl

Download URL mythicmc_sdk-0.1.0-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d13c121bec1d5ed0150cb18643d36ed3cb436aaa425f97c4cea032a9faf1155
BLAKE2b-256 checksum
How to use checksums
cd9cc4c1dd68180c1db15863dc26bd35c457340a6b150fb05a46fa5159a641da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

0.1.0 This release

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