Skip to main content

eternal-return-api (Python)

Unofficial Python client for the Eternal Return Open API, with sync and asyncio clients.

The code comes from ERCraft, an Eternal Return stats site that runs on this API. It is the Python version of the npm package of the same name, and handles what stats sites and bots need beyond plain requests:

  • New games only. sync_user_games stops at the newest game you have, so a player with a few new games costs one request.
  • Unfinished games. A game fetched while other teams are still playing has no winner yet. is_game_finished tells you, and get_game does not cache it.
  • Watching players. watch_games reports games as players finish them, for Discord bots and alerts.
  • Rate limiting, 429 retries, and error codes inside HTTP 200 responses.
  • Teams (group_teams), RP before and after a game (rp_change), AI players (is_bot_player), tiers from RP (rank_tier), and names for characters, items, traits, weapons and tactical skills from the official localization file.

한국어 · Field guide

Python 3.10+. One dependency: httpx. Rows are plain dicts with the API's own field names, typed with TypedDict.

Install

pip install eternal-return-api

Use

import os
from eternal_return_api import ErClient, group_teams, rank_tier, summarize_games

with ErClient(os.environ["ER_API_KEY"]) as er:
    user = er.get_user_by_nickname("Nickname")
    if user is None:
        raise SystemExit("No such player")

    seasons = er.get_seasons()
    season_id = seasons.current_ranked_season_id
    rank = er.get_user_rank(user["uid"], season_id)

    names = er.get_names("English")
    if rank:
        tier = rank_tier(rank["mmr"], rank=rank["rank"], season=seasons.player_season_of(season_id))
        print(tier.name)  # "Diamond 2"

    games = list(er.iter_user_games(user["uid"], max_pages=2))
    for game in games:
        print(names.character(game["characterNum"]), names.weapon(game.get("bestWeapon")), game["gameRank"])

    summary = summarize_games(games)
    teams = group_teams(er.get_game(games[0]["gameId"]))

AsyncErClient has the same methods as coroutines:

from eternal_return_api import AsyncErClient

async with AsyncErClient(api_key) as er:
    user = await er.get_user_by_nickname("Nickname")
    async for game in er.iter_user_games(user["uid"], max_pages=1):
        ...

Get an API key at developer.eternalreturn.io. Keep it on your server.

Keeping up with new games

Stats sites and bots fetch the same players again and again, so paging through the whole list each time wastes requests.

from eternal_return_api import is_game_finished

result = er.sync_user_games(uid, after=saved_newest)  # one request when there are a few
db.save_games(result.games)
db.save_newest(player.id, result.newest_game_id)  # your own id, not the uid

# A game fetched while other teams are still playing has no winner yet.
players = er.get_game(result.games[0]["gameId"])
if is_game_finished(players):
    db.save_game(players)
  • A player's games are sorted by gameId, newest first, and the API's next cursor is a game id. after stops at a game you have; before starts below a given game in one request.
  • With max_pages, sync_user_games may stop before reaching after. It then sets rest: call er.sync_user_games(uid, **result.rest) until no rest is returned. Until then newest_game_id stays at the old after, so saving it never skips games.
  • Without after, it reads the whole list (about 90 days). Pass since or max_pages for a first sync.

ERCraft once stored games fetched mid-game as final, and team records showed teammates as missing. On the live API, a normal game fetched 14 minutes after it started had 6 rows; eight minutes later it had 15 and still no winner. is_game_finished looks for a row with gameRank 1, or, in games with AI players, for a start more than an hour ago: a game an AI team won can have no such row. Call it right after fetching. Row count alone is not enough: finished games can have fewer than 24 rows.

Watching players

import asyncio
from eternal_return_api import AsyncErClient, GameEvent

watched = {uid}

async def post_results(er: AsyncErClient) -> None:
    async for event in er.watch_games(lambda: watched, interval=60):
        if isinstance(event, GameEvent):
            print(event.uid, event.game["gameRank"], event.game["playerKill"])
        else:
            print("failed", event.uid, event.error)
  • The first round only notes each player's newest game; past games are not reported. To resume after a restart, pass after={uid: game_id} with the last game you handled, under the uid you watch with. after is read when a player first appears, so a bot can set an entry before adding a player.
  • Each round costs one request per player when nothing is new, and skips the cache. At the default 1 request per second, 60 players take a minute per round.
  • A failed request for one player comes as an ErrorEvent. Watching goes on, and the next round tries again.
  • uids may be a function: it is called before every round, so you can add and remove players. A removed player starts fresh when added back.
  • Stop by cancelling the task, or pass stop=asyncio.Event() and set it. The sync client takes a threading.Event.
  • event.game is the player's own row. Other teams may still be playing, so check is_game_finished before storing get_game results.

API

Method Returns when not found
get_user_by_nickname(nickname) None
get_user_games(uid, next=None) empty page
iter_user_games(uid, *, after, before, since, max_pages) ends
sync_user_games(uid, *, after, before, since, max_pages) no games
watch_games(uids, *, interval, after, stop) keeps watching
get_game(game_id) []
get_user_rank(uid, season_id, team_mode=3) None, also without a ranked game in the season
get_top_ranks(season_id, team_mode=3, server_code=None) []
get_user_stats(uid, season_id, matching_mode=3) []
get_data(meta_type) raises
get_seasons() raises
get_l10n(language), get_names(language) raises
request(path) raises

API errors and timeouts raise ErApiError with status and api_code. A nickname lookup that returns a different player raises ErNicknameMismatchError. Network errors from httpx are passed through.

The uid is for requests only. Each nickname lookup returns a different one, so do not use it as a key in your own data.

Options

ErClient(
    api_key,
    requests_per_second=1,   # match your key's limit
    burst=1,
    timeout=9.0,             # seconds, per request
    retry_delays=(1.5, 3.0), # waits before each retry after HTTP 429; () disables
    cache=None,              # MemoryCache() or your own store
    cache_ttl=None,          # seconds per kind, e.g. {"userGames": 30}
    http_client=None,        # your own httpx.Client
)

Cache

Off by default. MemoryCache() keeps responses in memory; any object with get(key) and set(key, value, ttl) works, and the async client also accepts coroutine methods (for example an async Redis client). Default times: nickname 10 minutes, user games and rank 1 minute, top ranks and stats 5 minutes, games and data tables 1 hour. A failing cache counts as a miss. In the async client, concurrent calls for the same cached path share one request.

Testing without an API key

eternal_return_api.testing serves made-up responses in the shape of the real API: two ranked games with every player, the leaderboard, and the tables and localization keys they need. Nothing in them comes from the API: names, codes and numbers are invented. The field names and the relations between fields follow the real API, as described in the field guide.

from eternal_return_api.testing import SAMPLE_NICKNAME, sample_client

er = sample_client()
user = er.get_user_by_nickname(SAMPLE_NICKNAME)

async_sample_client() is the async version, and sample_transport() is the httpx transport behind both.

Not included

  • Retrying network errors other than 429.
  • Storing games. Games expire after about 90 days, so keep them in your own database.
  • Replay files.

License

MIT, for the code of this library only. Game data, text and other resources belong to Nimble Neuron and are not covered by this license. This is an unofficial project, not affiliated with or endorsed by Nimble Neuron.

Metadata

Release files for eternal-return-api 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 eternal-return-api 0.2.0
File Size Uploaded Provenance Actions
eternal_return_api-0.2.0.tar.gz 57.3 kB With provenance Details for eternal_return_api-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 104.0 kB

Release files / eternal_return_api-0.2.0.tar.gz

Download URL eternal_return_api-0.2.0.tar.gz
Size 57.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e7c1cd89c1f7557a9dec1c35cdaab77eb538a53cdeb65502b0e9efd753eeadcf
BLAKE2b-256 checksum
How to use checksums
a592e71d097d624943baf3a2e5c326e13205c1f2c8d43ef1fbeaedc39657b77d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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

Download URL eternal_return_api-0.2.0-py3-none-any.whl
Size 46.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ce51b0041cd3609530a3218abee37b7c30e56eea02b9e4d8f091b4aa2ec9fd1
BLAKE2b-256 checksum
How to use checksums
7e1ab31b4316914bf2516f24969070cb5e654b1ffd36e38d204e5da72336fa25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for eternal-return-api 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for eternal_return_api-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

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