Common Custom Types
Relevant source files
The following files were used as context for generating this wiki page:
Common custom types define the foundational data structures and type aliases used throughout the faceit-python library. These types ensure consistency in data validation, API communication, and internal logic handling, particularly for platform-specific identifiers and formatting requirements.
The library uses these types to wrap raw API data into Pydantic models, providing type safety for identifiers like player IDs, match IDs, and specialized URL formats.
Identifier Types
The library implements specific types for FACEIT platform identifiers. These types often wrap UUIDs or strings with specific prefixes to distinguish between different entity types.
Faceit ID Variants
| Type Name | Base Requirement | Description |
|---|---|---|
FaceitID | Valid UUID | Represents a standard FACEIT unique identifier, typically for players. |
FaceitTeamID | "team-" + UUID | Represents a unique identifier for teams. |
FaceitMatchID | "1-" + UUID | Represents a unique identifier for matches. |
Sources: tests/test_custom_types.py:46-105, src/faceit/models/players/match.py:20-23
Validation Logic
The library validates these identifiers during Pydantic model instantiation. FaceitID accepts standard UUID strings and handles cases with extra suffixes (e.g., "gui"). FaceitTeamID and FaceitMatchID require specific string prefixes and fail validation if the prefix is missing or the UUID portion is malformed.
Sources: tests/test_custom_types.py:46-105
Specialized Data Types
Temporal Types
The library differentiates between various timestamp formats returned by the FACEIT API:
TimestampMs: Unix time in milliseconds.TimestampSec: Unix time in seconds.NotStrictTimestampMs: Used in API parameters where timestamp formatting may be less rigid.
Sources: src/faceit/models/players/match.py:24-25, src/faceit/api/data/players.py:53
URL and Network Types
LangFormattedAnyHttpUrl: A specialized URL type that handles language placeholders. It strips or replaces/{lang}/placeholders from URLs to produce valid, accessible links.UrlOrEmpty: A union type accepting a valid PydanticAnyHttpUrlor an empty string ("").
Sources: tests/test_custom_types.py:22-43, src/faceit/types.py:50
API and Resource Types
These types facilitate the internal routing and response handling of the library.
API Response Formats
The library allows users to toggle between raw dictionary responses and parsed Pydantic models.
Raw: ANewTypeofboolrepresenting raw dictionary output.Model: ANewTypeofboolrepresenting parsed Pydantic model output.RawAPIItem: An alias fordict[str, Any].RawAPIPageResponse: ATypedDictfor paginated results includingitems,start, andend.
Sources: src/faceit/types.py:54-73
Resource Mapping
The library uses MappedValidatorConfig to dynamically select the correct model based on the game context (e.g., selecting CS2MatchPlayerStats when the game parameter is cs2).
Skill and Level Types
Skill levels are tied to specific games and ELO ranges.
SkillLevel Class
The SkillLevel class represents a player's rank. It includes:
level: An integer from 1 to 10.game_id: The specific game (e.g.,cs2).elo_range: AnEloRangeobject defining the boundaries.
Region and Game Enumerations
GameID: AStrEnumcontaining identifiers for supported games likeCS2,DOTA2, andVALORANT.Region: AStrEnumfor geographical regions (e.g.,EU,NA,SA).
Sources: src/faceit/constants.py:53-157, src/faceit/constants.py:244-250
Summary
Common Custom Types provide the structural integrity for the faceit-python package. By defining explicit types for platform identifiers (UUIDs with prefixes), temporal data (milliseconds vs seconds), and API response structures, the library maintains high type safety and reduces runtime errors during data parsing.