Rankings API Resource
Relevant source files
The following files were used as context for generating this wiki page:
The Rankings API Resource retrieves global and regional player leaderboards from the FACEIT platform. It allows developers to query rankings for specific games, regions, and countries, as well as locate a specific player's position within those leaderboards.
The resource is part of the faceit.api.data module and integrates with the library's pagination system to handle large datasets. It supports both synchronous and asynchronous execution through SyncRankings and AsyncRankings classes.
Sources: src/faceit/api/data/rankings.py, src/faceit/api/data/init.py:76-118
Resource Architecture
The Rankings resource follows the standard inheritance pattern used throughout the library. It inherits from BaseResource and utilizes a generic response format.
The diagram shows the hierarchy of the Rankings resource, where specialized sync and async classes implement the core ranking logic.
Sources: src/faceit/api/data/rankings.py:23-45, src/faceit/api/base.py:53-62
Core Components and Logic
The Rankings resource operates on the rankings endpoint path. It accepts several identifiers to filter leaderboard data.
Request Parameters
Rankings requests use the following parameters to scope the data:
| Parameter | Type | Description |
|---|---|---|
game | GameID | The specific game (e.g., CS2, CSGO). |
region | RegionIdentifier | The geographic region (e.g., EU, US, NA). |
country | CountryCode | Optional ISO country code for national rankings. |
player_id | PlayerID | Unique identifier for a player to find their rank. |
Sources: src/faceit/api/data/rankings.py:46-56, src/faceit/constants.py:84-142
Ranking Retrieval Flow
When you call a ranking method, the resource builds the URL path dynamically and attaches query parameters for pagination.
The flowchart illustrates the endpoint construction and data validation process for ranking queries.
Sources: src/faceit/api/data/rankings.py:64-77, src/faceit/api/base.py:127-148
Pagination Handling
The Rankings resource uses SyncPageIterator and AsyncPageIterator to manage large leaderboard lists. The all_unbounded method provides an automated way to collect multiple pages of ranking data.
Pagination Constraints
- Default Limit: 20 items per page.
- Maximum Limit: 100 items per page.
- Default Collection: Collects up to 10 pages by default when using
all_unbounded.
Sources: src/faceit/api/data/rankings.py:86-104, src/faceit/api/pagination.py:157-175
Implementation Example
The following snippet demonstrates how the SyncRankings class constructs requests for regional leaderboards.
@validate_call
def unbounded(
self,
game: GameID,
region: RegionIdentifier,
country: CountryCode | None = None,
*,
offset: int = Field(0, ge=0),
limit: int = Field(20, ge=1, le=100),
) -> RawAPIPageResponse | ItemPage[ModelNotImplemented]:
return self._validate_response(
self._client.get(
self.__class__.PATH / "games" / game / "regions" / region,
params=self.__class__._build_params(
country=country, offset=offset, limit=limit
),
expect_page=True,
),
ModelPlaceholder,
)
Sources: src/faceit/api/data/rankings.py:64-84
Conclusion
The Rankings API Resource provides a type-safe interface for accessing FACEIT leaderboards. By utilizing the library's internal pagination and validation logic, it ensures that developers can fetch either raw JSON data or validated models for global, regional, or player-specific ranking contexts.