API Resource Aggregators
Relevant source files
The following files were used as context for generating this wiki page:
API Resource Aggregators organize multiple specialized API resources into a single entry point. They manage the lifecycle of HTTP clients and provide access to both raw and model-validated versions of resources like players, matches, and teams. Sources: src/faceit/api/aggregator.py:32-34, src/faceit/api/data/init.py:60-61
Core Architecture
The system uses a hierarchical structure where a base aggregator manages the underlying httpx client, and a class decorator dynamically injects resource properties. Sources: src/faceit/api/aggregator.py:53-73
Aggregator Class Hierarchy
The library provides separate base classes for synchronous and asynchronous operations. Each specific resource implementation, such as SyncDataResource, inherits from these bases to establish client management behavior. Sources: src/faceit/api/aggregator.py:32-51, src/faceit/api/data/init.py:60-61
Diagram shows the relationship between base aggregator classes and concrete resource implementations. Sources: src/faceit/api/aggregator.py:32-51, src/faceit/api/data/init.py:60-85
Dynamic Resource Injection
The @resource_aggregator decorator inspects class annotations to create properties for each declared resource. It supports two modes of data access:
- Model Mode: Returns data parsed into Pydantic models.
- Raw Mode: Returns unprocessed dictionaries directly from the API.
The decorator distinguishes these modes by checking if the type hint contains the Raw marker. Sources: src/faceit/api/aggregator.py:53-73
| Component | Description |
|---|---|
BaseResources | Manages the internal httpx client and authentication. |
@resource_aggregator | Injects cached properties for API resources based on type hints. |
SyncDataResource | The primary entry point for synchronous FACEIT Data API access. |
AsyncDataResource | The primary entry point for asynchronous FACEIT Data API access. |
| Sources: src/faceit/api/aggregator.py, src/faceit/api/data/init.py |
Client Initialization and Authentication
Aggregators handle the creation of SyncClient or AsyncClient instances. You can provide an API key directly, pass an existing client, or let the system fetch the key from environment variables. Sources: src/faceit/api/aggregator.py:36-47, src/faceit/http/client.py:91-100
Diagram shows the decision logic for authenticating and initializing the underlying HTTP client. Sources: src/faceit/api/aggregator.py:36-47, src/faceit/http/client.py:145-151
Context Management
Sync and Async aggregators implement context manager protocols. Entering the context opens the underlying HTTP client, and exiting ensures all connections close properly. Sources: src/faceit/api/aggregator.py:44-51
Implementation of Data Resources
The SyncDataResource and AsyncDataResource classes aggregate specific endpoints into a unified interface. Each resource (e.g., players) is available in both standard and raw_ variants. Sources: src/faceit/api/data/init.py:60-104
Available Sub-Resources
| Resource Name | Raw Variant | Base Class |
|---|---|---|
players | raw_players | BasePlayers |
matches | raw_matches | BaseMatches |
teams | raw_teams | BaseTeams |
games | raw_games | BaseGames |
championships | raw_championships | BaseChampionships |
| Sources: src/faceit/api/data/init.py:62-85, src/faceit/api/data/players.py:50-54 |
Data Processing Flow
When you call a method on a sub-resource, the aggregator-managed client performs the request. The base resource then processes the response based on the raw flag set during property injection. Sources: src/faceit/api/base.py:80-112
Diagram illustrates the flow of data from the initial user request through the client and back through the validation layer. Sources: src/faceit/api/base.py:80-112, src/faceit/api/data/players.py:92-106
Summary
API Resource Aggregators serve as the centralized management layer for the FACEIT Python library. They encapsulate HTTP client complexity, enforce authentication via ValidUUID checks, and dynamically expose the API surface area through sub-resource properties. By utilizing the resource_aggregator decorator, the library maintains a clean separation between high-level user interfaces and low-level HTTP transport logic. Sources: src/faceit/api/aggregator.py, src/faceit/api/data/init.py