Raw Data vs Parsed Models
Relevant source files
The following files were used as context for generating this wiki page:
The faceit-python library provides two distinct ways to interact with FACEIT API data: raw dictionary access and type-safe Pydantic models. This dual-access architecture allows you to choose between the flexibility of unprocessed JSON responses and the safety of structured data objects.
Sources: README.md:14-15, src/faceit/api/data/init.py:75-101
Architectural Overview
The library organizes access through Data Resources, which aggregate various API endpoints. Each endpoint is exposed in two forms: a standard parsed version (e.g., players) and a raw version prefixed with raw_ (e.g., raw_players).
Resource Comparison
| Access Mode | Return Type | Validation | Use Case |
|---|---|---|---|
| Parsed Mode | Pydantic BaseModel or ItemPage | Strict Pydantic validation | Production code, type-safe analysis |
| Raw Mode | dict or list[dict] | None (Direct API JSON) | Prototyping, debugging, handling new/unmapped fields |
Sources: README.md:14-15, src/faceit/api/base.py:108-164, src/faceit/api/data/init.py:75-101
Data Flow Diagram
The following diagram illustrates how the library processes an API response based on the selected mode.
Sources: src/faceit/api/base.py:108-176
Raw Data Access
Raw access bypasses the library's internal model validation. It returns the exact structure provided by the FACEIT API as standard Python types.
Characteristics of Raw Mode
- Types: Responses are typed as
RawAPIItem(a dictionary) orRawAPIPageResponse(a typed dictionary for paginated data). - Flexibility: Useful when the API returns data for which models are not yet implemented in the library.
- Speed: Avoids the overhead of Pydantic validation.
Sources: src/faceit/types.py:46-63, src/faceit/api/base.py:108-112
Parsed Models
Parsed mode uses Pydantic to convert API responses into structured objects. This mode provides IDE autocompletion, type-checking, and data integrity.
ItemPage Collection
When fetching paginated data in parsed mode, the library wraps the results in an ItemPage collection. This class provides utility methods for data manipulation:
.filter(predicate): Filters items based on a condition..map(func): Transforms items in the collection..find(attr, value): Finds the first item where an attribute matches a value..get_first()/.get_last(): Safely retrieves items with optional defaults.
Sources: README.md:16, src/faceit/models/item_page.py:73-125
Validation Logic
The BaseResource class manages the validation process using _validate_response. If a validator is defined for an endpoint, the library attempts to parse the response.
def _validate_response(
self,
response: _ResponseT,
validator: type[ModelT] | None,
/,
*,
warn_msg: str | None = None,
) -> _ResponseT | ModelT:
if self._raw:
return response
if validator is None:
# Fallback to raw and warn if model is missing
return response
try:
return validator.model_validate(response)
except ValidationError:
if self._strict_validation:
raise
return response
Sources: src/faceit/api/base.py:151-176
Handling Paginated Data
Pagination behaves differently depending on the access mode, specifically regarding how "all" items are gathered from multiple API pages.
Pagination Process
| Return Format | Raw Mode Response | Parsed Mode Response |
|---|---|---|
| Single Page | RawAPIPageResponse (dict) | ItemPage[Model] |
| All Pages | list[RawAPIItem] | ItemPage[Model] (Merged) |
Sources: src/faceit/api/pagination.py:382-392, src/faceit/api/data/players.py:183-193
Conclusion
The distinction between raw data and parsed models allows faceit-python to support both rapid development and robust, type-safe applications. Parsed models provide significant developer ergonomics through the ItemPage utility methods and Pydantic validation, while raw mode ensures the library remains usable even as the underlying API evolves or return values remain unmapped.