Players API Resource
Relevant source files
The following files were used as context for generating this wiki page:
The Players API Resource manages interactions with FACEIT player data, including profile details, statistics, match history, and tournament participation. It provides both synchronous and asynchronous interfaces for fetching individual player objects or paginated collections of related entities. Sources: src/faceit/api/data/players.py:53-61, src/faceit/api/data/init.py:79-114
Architecture and Components
The resource is structured using a base class for shared logic and specialized classes for execution modes. It relies on a request-to-model pipeline that validates input parameters and parses raw API responses into structured Pydantic models. Sources: src/faceit/api/data/players.py:53-111, src/faceit/api/base.py:56-78
Core Classes
| Class | Description |
|---|---|
BasePlayers | Defines the players path and shared validation configurations for stats and matches. |
SyncPlayers | Implements synchronous blocking methods for player data retrieval. |
AsyncPlayers | Implements asynchronous non-blocking methods using await. |
Player | Pydantic model representing a player profile, including games, country, and memberships. |
Sources: src/faceit/api/data/players.py:53-704, src/faceit/models/players/general.py:73-95
Resource Logic Flow
The resource determines how to query the FACEIT API based on the provided identifier. If a UUID is detected, it queries by ID; otherwise, it treats the string as a nickname. Sources: src/faceit/api/data/players.py:91-111
The diagram shows the logic used in _process_get_request to select the correct endpoint and parameters. Sources: src/faceit/api/data/players.py:86-111
Key Features
Player Retrieval and Identification
Users fetch players using several identifiers. The resource supports player_id (UUID), nickname, or a combination of game and game_player_id. Sources: src/faceit/api/data/players.py:118-146
- UUID Lookup: Uses the direct path
/players/{player_id}. - Nickname Lookup: Uses the query parameter
?nickname={nickname}. - External ID Lookup: Uses
gameandgame_player_idparameters.
Statistics and Match History
The resource provides specialized methods for game-specific statistics. For Counter-Strike 2 (CS2), it uses CS2MatchPlayerStats and CSPlayerStats models to provide deep type safety for game-specific metrics like K/D ratio, ADR, and map-specific performance. Sources: src/faceit/api/data/players.py:63-80, src/faceit/models/players/match.py:121-155
Data Models
| Model | Fields | Source |
|---|---|---|
Player | id, nickname, games, verified, activated_at | general.py:73-95 |
CSPlayerStats | lifetime (K/D, Win Rate), segments (Maps) | general.py:270-274 |
CS2MatchPlayerStats | kd_ratio, adr, kills, deaths, map, result | match.py:121-155 |
BanEntry | nickname, type, reason, starts_at | general.py:101-107 |
Pagination System
Methods that return lists (bans, history, hubs, teams, tournaments) use the ItemPage container. This container supports advanced iteration and filtering. Sources: src/faceit/models/item_page.py:29-50, src/faceit/api/pagination.py:206-216
This diagram illustrates the flow for "all_" methods which automate the request of multiple pages. Sources: src/faceit/api/data/players.py:270-285, src/faceit/api/pagination.py:488-531
Pagination Parameters
| Parameter | Type | Default | Constraints |
|---|---|---|---|
offset | int | 0 | ge=0 |
limit | int | 20 | ge=1, le=100 |
start | TimestampMs | None | Range start (Unix ms) |
to | TimestampMs | None | Range end (Unix ms) |
Sources: src/faceit/api/data/players.py:186-215, src/faceit/api/pagination.py:102-120
Implementation Details
Response Validation
The resource uses MappedValidatorConfig to select the correct model based on the GameID. If no specific model is found for a game, it falls back to FallbackPlayerStats to ensure the application does not crash. Sources: src/faceit/api/data/players.py:71-80, src/faceit/api/base.py:104-121
# Validation configuration in BasePlayers
_stats_validator_cfg = MappedValidatorConfig[GameID, AnyPlayerStats](https://github.com/zombyacoff/faceit-python/blob/bbcb3c420e204dcfefe1305587401ab520f027df/validator_map%3D%7B%0A%20%20%20%20%20%20%20%20GameID.CS2%3A%20CSPlayerStats%2C%0A%20%20%20%20%20%20%20%20GameID.CSGO%3A%20CSPlayerStats%2C%0A%20%20%20%20%7D%2C%0A%20%20%20%20key_name%3D%22game%22%2C%0A%20%20%20%20default_validator%3DFallbackPlayerStats%2C)
Sources: src/faceit/api/data/players.py:71-80
Player Identifier Normalization
The _process_get_request helper method normalizes various inputs into a standard RequestPayload. It handles the logic for appending nicknames to params or constructing UUID-based URL paths. Sources: src/faceit/api/data/players.py:86-111
Conclusion
The Players API Resource provides a robust, type-safe wrapper for the FACEIT Players API. It abstracts the complexity of multiple identification methods and paginated data retrieval. By integrating game-specific models and automatic pagination iterators, it allows developers to focus on data analysis rather than HTTP request management. Sources: README.md:14-30, src/faceit/api/data/players.py:53-61