Matches API Resource
Relevant source files
The following files were used as context for generating this wiki page:
The Matches API Resource provides a programmatic interface to retrieve detailed information and statistics for specific matches on the FACEIT platform. It handles the communication between the Python client and the /matches endpoint of the FACEIT Data API.
This resource supports both synchronous and asynchronous execution modes. It allows users to request match details in either raw JSON format or as structured Pydantic models. The module ensures type safety by validating match identifiers before making API requests.
Sources: src/faceit/api/data/matches.py:1-11, src/faceit/api/data/init.py:79-80
Architecture and Components
The Matches API Resource follows a hierarchical structure inherited from a base resource class. It utilizes specialized clients for HTTP communication and incorporates validation logic for match identifiers.
Class Hierarchy
The resource is divided into three main classes:
BaseMatches: An abstract base class that defines the sharedresource_pathas "matches".SyncMatches: A final class for synchronous API calls usingSyncClient.AsyncMatches: A final class for asynchronous API calls usingAsyncClient.
Sources: src/faceit/api/data/matches.py:27-35, src/faceit/api/data/matches.py:38, src/faceit/api/data/matches.py:68
The diagram above shows the inheritance relationship between the match resource classes and the base resource framework.
Sources: src/faceit/api/data/matches.py:27-68, src/faceit/api/base.py:46
Data Flow
When a user calls a method on the Matches resource, the following sequence occurs:
- Validation: The
match_idis validated usingFaceitMatchIDlogic. - Request Construction: The client appends the match ID to the
PATH("matches"). - HTTP Call: The client performs a GET request to the FACEIT API.
- Response Processing: The
_validate_responsemethod checks the result against aModelPlaceholderor returns raw data based on the resource configuration.
Sources: src/faceit/api/data/matches.py:49-53, src/faceit/api/base.py:118-124
API Methods
The Matches resource implements two primary methods to access match data. Both methods use @validate_call to ensure input parameters meet type constraints at runtime.
Resource Endpoints
| Method | Endpoint | Description |
|---|---|---|
get() | /matches/{match_id} | Retrieves general information about a specific match. |
stats() | /matches/{match_id}/stats | Retrieves detailed statistics for a specific match. |
Sources: src/faceit/api/data/matches.py:51-65, tests/test_resources_integration.py:58-66
Input Validation
The resource uses a specific type alias _MatchIDValidated for match identifiers. This type includes an AfterValidator that applies the FaceitMatchID constraint. A valid Match ID typically follows the format 1-{uuid}, such as 1-729f64c6-47d3-4613-94c0-54f38712GUI.
Sources: src/faceit/api/data/matches.py:20-24, src/faceit/models/custom_types/faceit_uuid.py:53-58
Data Models
While many match models are currently handled via ModelPlaceholder in the API resource methods, the project defines several data structures to represent match components in src/faceit/models/players/match.py.
Match Component Models
| Class | Description | Key Fields |
|---|---|---|
Match | Represents the complete match entity. | id, game_id, region, teams, results |
Team | Represents a group of players in a match. | id, name, players |
Results | Contains match outcome data. | winner, score |
PlayerSummary | Brief info about a player within a match. | nickname, skill_level, faceit_url |
The ER diagram illustrates the relationship between match components and player data within the FACEIT match structure.
Sources: src/faceit/models/players/match.py:42-110
Usage Implementation
The resource is typically accessed through the SyncDataResource or AsyncDataResource aggregators. These aggregators provide both a model-validated version (e.g., .matches) and a raw version (e.g., .raw_matches) of the resource.
# Example of match retrieval via the aggregator
data = SyncDataResource(api_key="...")
# Get raw JSON match data
raw_match = data.raw_matches.get("1-729f64c6-47d3-4613-94c0-54f38712GUI")
# Get match statistics
match_stats = data.raw_matches.stats("1-729f64c6-47d3-4613-94c0-54f38712GUI")
Sources: src/faceit/api/data/init.py:81-82, tests/test_resources_integration.py:58-66
Summary
The Matches API Resource serves as a critical component for accessing match-specific data within the faceit-python library. It validates match IDs, handles the routing to /matches endpoints, and provides developers with a choice between raw JSON data and structured Python models for both synchronous and asynchronous workflows.