Games API Resource
Relevant source files
The following files were used as context for generating this wiki page:
The Games API Resource manages interactions with the /games endpoint of the FACEIT Data API. It retrieves information about games supported by the FACEIT platform, providing both individual page fetching and full collection utilities.
This resource is integrated into the primary SyncDataResource and AsyncDataResource entry points. It supports two operation modes: Raw, which returns dictionaries, and Model, which attempts to parse responses into Pydantic objects. Sources: src/faceit/api/data/games.py:1-25, src/faceit/api/data/init.py:65-71
Resource Architecture
The Games resource follows the project's standard resource pattern by inheriting from BaseResource. It uses the resource_path="games" configuration to set the base endpoint.
Key Classes
| Class | Description |
|---|---|
BaseGames | Abstract base class defining the games path. |
SyncGames | Implementation for synchronous HTTP calls using SyncClient. |
AsyncGames | Implementation for asynchronous HTTP calls using AsyncClient. |
SyncPageIterator | Utility used by all_items to fetch all pages synchronously. |
AsyncPageIterator | Utility used by all_items to fetch all pages asynchronously. |
Sources: src/faceit/api/data/games.py:28-115, src/faceit/api/pagination.py:417-525
API Endpoints and Parameters
The resource interacts with the https://open.faceit.com/data/v4/games endpoint. Methods within this resource allow for paginated retrieval of game data.
Request Parameters
| Parameter | Type | Default | Constraints | Description |
|---|---|---|---|---|
offset | int | 0 | >= 0 | The starting position in the collection. |
limit | int | 20 | 1 to 100 | The number of items to return per page. |
max_items | int | "safe" | "safe" | - | Total items to collect across all pages. |
Sources: src/faceit/api/data/games.py:46-51, src/faceit/api/pagination.py:133-138
Data Flow: Fetching Items
The resource uses a layered approach to fetch data. The items method performs a single request, while all_items leverages an iterator to handle multiple requests until the requested count or end of data is reached.
Implementation Detail: all_items
The all_items method utilizes SyncPageIterator or AsyncPageIterator. These iterators automatically calculate the necessary offsets and limits to satisfy the max_items requirement.
# src/faceit/api/data/games.py:65-73
def all_items(
self, max_items: MaxItemsType = "safe"
) -> list[RawAPIItem] | ItemPage[ModelNotImplemented]:
iterator = SyncPageIterator(self.items, max_items=max_items)
return iterator.collect()
Response Formats
The resource returns different types based on the APIResponseFormatT generic type, which is typically set during the initialization of the DataResource.
- Raw Mode (
Raw): ReturnsRawAPIPageResponse(a dictionary) containing a list ofRawAPIItemobjects. - Model Mode (
Model): Returns anItemPagecollection. Currently, since the Game model is not fully implemented in the provided files, it usesModelNotImplemented(a placeholder forBaseModel).
Sources: src/faceit/api/data/games.py:43-62, src/faceit/types.py:64-79, src/faceit/api/base.py:101-118
Pagination Metadata
When using ItemPage, the resource includes pagination metadata derived from the API response headers/body:
start(mapped tooffset)end(mapped tolimit)items(the actual list of game objects)
Sources: src/faceit/models/item_page.py:38-55, src/faceit/types.py:73-82
Summary
The Games API Resource provides a standardized way to access FACEIT game data. It supports both sync and async operations and abstracts complex pagination logic through the PageIterator system. Developers can choose between raw dictionary responses for flexibility or model-based responses for type safety, even as specific game models are being developed. Sources: src/faceit/api/data/games.py