FACEIT UUID Handling
Relevant source files
The following files were used as context for generating this wiki page:
FACEIT UUID Handling defines the logic for validating and parsing unique identifiers used across the FACEIT platform. This system ensures that IDs for players, teams, and matches adhere to specific formats, including handling platform-specific inconsistencies like suffixes and prefixes. By centralizing this logic, the library provides type-safe interactions with the FACEIT API and prevents malformed data from entering the application state.
Architecture and Validation Logic
The core of UUID handling resides in src/faceit/models/custom_types/faceit_uuid.py. It uses a base validator class and specific implementations for different ID types. The validation logic integrates with Pydantic via the __get_pydantic_core_schema__ method, allowing automatic validation when data is parsed into models.
Class Hierarchy
The system uses an abstract base class _BaseFaceitUUIDValidator to define common validation steps, such as removing prefixes and suffixes before performing a standard UUID check.
Validation Flow
When a string is processed as a FACEIT ID, the validator performs several steps to normalize the data.
- Suffix Removal: The system strips the
"gui"suffix from IDs. This handles an inconsistency discovered in account friend lists where some UUIDs fail standard validation. - Prefix Check: Specific ID types (Matches and Teams) check for a required prefix.
- UUID Verification: The remaining string must pass a standard UUID format check.
Core ID Types
The library distinguishes between generic IDs and resource-specific IDs that require prefixes.
| Class | Description | Required Prefix | Suffix Handling |
|---|---|---|---|
FaceitID | Standard player or hub identifier. Inherits from uuid.UUID. | None | Strips "gui" |
FaceitMatchID | Specific identifier for match entities. | "1-" | Strips "gui" |
FaceitTeamID | Specific identifier for team entities. | "team-" | Strips "gui" |
Sources: src/faceit/models/custom_types/faceit_uuid.py:44-86
Handling Optional IDs
The type alias MaybeFaceitID allows a field to contain either a valid FaceitID or an empty string, accommodating API responses where an ID might be missing or not yet assigned.
Sources: src/faceit/models/custom_types/faceit_uuid.py:58
Integration in Data Models
Data models use these custom types to enforce strict typing across the API resource modules.
- Player Model: Uses
FaceitIDforplayer_idand thefriends_idslist.
Sources: src/faceit/models/players/general.py:84-93 - Match Model: Uses
FaceitMatchIDfor match identifiers in statistics, ensuring the"1-"prefix is present.
Sources: src/faceit/models/players/match.py:126-127 - Team Model: Uses
FaceitIDfor fields liketeam_idandleader_id.
Sources: src/faceit/models/players/general.py:124-135
Model Validation Example
In the CS2MatchPlayerStats model, the field id is annotated with FaceitMatchID. When the API returns a match ID, Pydantic uses the FaceitMatchID._validate method to ensure the string begins with "1-" and contains a valid UUID.
Sources: src/faceit/models/players/match.py:127, src/faceit/models/custom_types/faceit_uuid.py:79-81
API Resource Validation
The API resources validate IDs passed as arguments to ensure requests are well-formed before they are sent to the FACEIT servers.
- Matches Resource: The
getandstatsmethods validate thematch_idusingFaceitMatchID.
Sources: src/faceit/api/data/matches.py:19-22 - Players Resource: Uses a specialized
validate_player_idhelper viaAfterValidatorto ensure UUID integrity for player-related queries.
Sources: src/faceit/api/data/players.py:60-61 - Championships Resource: Validates
championship_idusing a UUID validator created bycreate_uuid_validator.
Sources: src/faceit/api/data/championships.py:33-37
Summary
FACEIT UUID Handling provides a robust validation layer that handles the nuances of the FACEIT API's identification system. By implementing custom Pydantic validators, the library automatically cleanses inconsistent data (such as the "gui" suffix) and enforces mandatory prefixes for matches and teams. This architecture ensures high data integrity and type safety for developers interacting with player, match, and team resources.