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

API 1.1.0

See release notes for breaking changes and migration instructions.

Resource TypeScript Python (sync and async)
SurvivalShop getSurvivalShop get_survival_shop
PlayerShopBundles getPlayerShopBundles get_player_shop_bundles
BountyClaimPage listBountyClaims list_bounty_claims
BountyClaim getBountyClaim get_bounty_claim
EventDetails getEventDetails get_event_details
EventSchedulePage listEventSchedules list_event_schedules
EventSchedule getEventSchedule get_event_schedule
StallPage listStalls list_stalls
Stall getStall get_stall
BountyPage listBounties list_bounties
Bounty getBounty get_bounty

List methods take pagination options ({ limit, cursor } in TypeScript; keyword arguments in Python). Follow nextCursor / next_cursor until null. IDs are URL-encoded. Shop reads optionally accept an ETag and return null / None on 304; otherwise use reply.meta.etag for the next conditional request.

Release files for mythicmc-sdk 1.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 1.1.0
File Size Uploaded
mythicmc_sdk-1.1.0.tar.gz 18.6 kB Details

Built distribution (wheel)

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

Total release size: 31.4 kB

Release files / mythicmc_sdk-1.1.0.tar.gz

Download URL mythicmc_sdk-1.1.0.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b767a2811fe38f0fec4dc8bec3c28cad3bf2705458e6e6fd97187337f06cd20
BLAKE2b-256 checksum
How to use checksums
36e89b4f4c21fdcfe7a56f2cdba37dbefea909289d8347b007295d7c6ee9c69b
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-1.1.0-py3-none-any.whl

Download URL mythicmc_sdk-1.1.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28cb1a50cebed5dc1c2345e2235f81637ae6c95c5de5f7ac7157f2d2db1d3cb6
BLAKE2b-256 checksum
How to use checksums
20cb4b9b7021abcaa3db78d07eed95a9b1014ec4339d89c3fa4242c125a17ba5
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

This release

1.1.0 This release

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