Metadata-Version: 2.5
Name: rivalsisland
Version: 0.7.0
Summary: Marvel Rivals API client for Python: player stats, match history, leaderboards, live games and teammates.
Project-URL: Homepage, https://api.rivalsisland.com
Project-URL: Documentation, https://api.rivalsisland.com/docs
Project-URL: Changelog, https://api.rivalsisland.com/changelog
Author: RivalsIsland
License-Expression: MIT
License-File: LICENSE
Keywords: async,esports,game-api,leaderboard,marvel rivals,marvel-rivals,marvel-rivals-api,marvel-rivals-stats,marvelrivals,match-history,rivalsisland,sdk,stats,tracker
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Games/Entertainment
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: typing-extensions>=4.6
Provides-Extra: dev
Requires-Dist: build>=1; extra == 'dev'
Requires-Dist: mypy>=1.14; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Requires-Dist: twine>=6; extra == 'dev'
Description-Content-Type: text/markdown

# RivalsIsland: Marvel Rivals API for Python

The Python SDK for the [RivalsIsland API](https://api.rivalsisland.com/docs).
Look up Marvel Rivals players, careers, matches, live games and teammates, browse
the game catalog, and read leaderboards with synchronous or asynchronous clients.

Unofficial: RivalsIsland is not affiliated with or endorsed by Marvel, NetEase Games or Disney.

**Python 3.10+ · API 2.5.0 · SDK 0.7.0 · MIT**

- All 36 public operations, with 133 generated response types.
- Sync and async httpx clients, connection reuse, proxies and custom transports.
- Credit metadata, typed errors and automatic rate-limit retries.
- History iteration with deduplication and an optional limit on paid page requests.
- Original API field names and values; additional response fields are retained.

## Install

```sh
python -m pip install rivalsisland
```

Get a key from the [dashboard](https://api.rivalsisland.com/dashboard)
and set `RIVALSISLAND_API_KEY` in your environment. Keep it in your environment or
secret manager; the SDK sends it in `x-api-key`, never in the URL.

## Your first request

```python
from rivalsisland import RivalsIsland

with RivalsIsland() as api:  # Reads RIVALSISLAND_API_KEY.
    player = api.search("lucifwr").data.get("player")
    if player is None:
        raise LookupError("No player named lucifwr was found")
    result = api.player(player["uid"])
    print(result.data["name"], result.data.get("account_level"))
    print("Credits left:", result.meta.credit_balance)
```

Every call returns `Result[T]`: `data` is the response dictionary; `meta` contains
credit/rate headers and the request ID. This example costs 10 credits on success.
You can also pass `RivalsIsland(api_key=...)` directly.

## Async works the same way

```python
import asyncio
from rivalsisland import AsyncRivalsIsland

async def main():
    async with AsyncRivalsIsland() as api:
        player = (await api.search("lucifwr")).data.get("player")
        if player is not None:
            print((await api.career(player["uid"])).data)

asyncio.run(main())
```

Reuse clients across calls. Context managers close SDK-owned connections; injected
httpx clients remain yours to close.

## Iterate recent matches

```python
from datetime import datetime, timedelta, timezone
from rivalsisland import RivalsIsland

with RivalsIsland() as api:
    player = api.search("lucifwr").data.get("player")
    if player is None:
        raise LookupError("No player named lucifwr was found")
    for match in api.iter_match_history(
        player["uid"], since=datetime.now(timezone.utc) - timedelta(days=1),
        page_size=20, max_pages=2, known_match_uids=set(),
    ):
        print(match["match_uid"], match["played_at"])
```

Pages start at 0. `max_pages` caps requests; omit it to continue while `has_more`
is true. Each page costs credits. The helper copies your known-ID set and skips
duplicates. For incremental sync, overlap your last sync time to catch late custom
rooms. A capped run is a partial snapshot, so do not treat its end as a complete sync.

## Errors and configuration

```python
from rivalsisland import APIError, RateLimitError, RivalsIsland, TransportError

with RivalsIsland(max_retries=3, timeout=30) as api:
    try:
        player = api.search("lucifwr").data.get("player")
        if player is not None:
            result = api.detailed_match_history(player["uid"], page_size=20, timeout=90)
    except RateLimitError as error:
        print("Retry delay:", error.retry_after)
    except APIError as error:
        print(error.status, error.code, error.error_id, error.request_id)
    except TransportError:
        print("The request could not be completed.")
```

429 and 502/503/504 retry up to three times, honoring numeric `Retry-After` seconds.
Fallback exponential backoff starts at 0.5 seconds with jitter and caps at 30 seconds.
Other 4xx and 500 do not retry. Set `max_retries=0` to disable retries.
Invalid local parameters raise `ValueError`; network failures raise `TransportError`.

| Constructor option | Default | Purpose |
|---|---|---|
| `api_key` | Environment variable | Authentication |
| `base_url` | `https://api.rivalsisland.com` | Alternate deployment |
| `timeout` | 30 seconds | httpx timeout per phase, per attempt |
| `max_retries` | 3 | Retries after the initial attempt |
| `http_client` | SDK-owned client | Proxy, pooling and custom configuration |
| `transport` | httpx default | Injectable test transport |

Every method accepts `timeout=`. Pass either `http_client` or `transport`.
Timeouts are not an overall elapsed-time deadline across retries.

## Credits and access

Catalog/leaderboard calls cost 1 credit; search/profile and several player routes
cost 5; career and punishments cost 10. Unfiltered history costs 10 per started 20
requested matches, or 100 for detailed history. Filters use returned-match and
scan-based pricing. Errors cost zero; response headers are authoritative.

`proficiency`, `rank_history`, `cosmetics` and `punishments` require a paid plan.
Free gets 403 `premium_required`; profile `is_online` and `discord` are `None` on
Free. Privacy can restrict data on any plan. [Prices for every endpoint](https://api.rivalsisland.com/docs).

## Examples and documentation

| Resource | Contents |
|---|---|
| Match viewer website (`examples/match-viewer/README.md` in the source package) | Runnable player/profile and recent-games site, with demo mode |
| Player-card project (`examples/player-card/README.md` in the source package) | Search, profile and metadata |
| Match-report project (`examples/match-report/README.md` in the source package) | Bounded pagination and JSON export |
| Async script (`examples/async_profile.py` in the source package) | Async profile lookup |
| [API reference](https://api.rivalsisland.com/docs) | All 36 endpoints, parameters and prices |
| Detailed reference (`docs/reference.md` in the source package) | Parameter types, bounds and response types |
| Full guide (`docs/guide.md` in the source package) | Errors, metadata, credits and time handling |

Response types in `rivalsisland.models` are permissive TypedDicts. New fields are
preserved at runtime. `parse_time(value)` returns an aware UTC datetime; raw ISO
strings/Unix seconds stay unchanged. Naive `since` datetimes mean UTC. New endpoints
and input enum values need an SDK update; breaking API changes require migration.
See the [API changelog](https://api.rivalsisland.com/changelog).

## Development

```sh
python -m pip install -e '.[dev]'
ruff check src tests examples
mypy --strict
pytest
python -m build
python -m twine check --strict dist/*
```

Offline tests use mocked HTTP and loopback servers; no API key is required.
CI covers Python 3.10–3.14. The source archive includes the example projects and
docs; the wheel includes typing metadata. MIT license.
