Quickstart Guide
Relevant source files
The following files were used as context for generating this wiki page:
The faceit-python library provides a type-safe, idiomatic Python interface for the FACEIT Data API. It supports both synchronous and asynchronous operations, Pydantic-based data modeling, and advanced pagination utilities.
Sources: README.md:1-24, src/faceit/api/data/init.py:1-115
Installation
The library requires Python 3.10 or higher. You install the core package via pip.
pip install faceit
To enable automatic environment variable loading for API keys, install the env extra.
pip install faceit[env]
Sources: README.md:26-38, pyproject.toml:13
Authentication and Initialization
The library uses API keys for authentication. You obtain these keys from the FACEIT Developer Portal.
API Key Handling
You can provide the API key in three ways:
- Manual: Pass the key string directly to the resource constructor.
- Automatic: Set the
FACEIT_API_KEYenvironment variable (requiresfaceit[env]). - Custom Variable: Pass a
FromEnv("YOUR_VAR_NAME")instance to the constructor.
Sources: README.md:73-81, src/faceit/http/client.py:94-118
Resource Aggregators
The library organizes endpoints into DataResource objects. You choose between SyncDataResource for standard scripts or AsyncDataResource for asynchronous applications.
The diagram shows the relationship between user resources, internal HTTP clients, and the FACEIT API.
Sources: src/faceit/api/data/init.py:60-115, src/faceit/http/client.py:165-215
Basic Usage
The following example demonstrates fetching player data and analyzing matches using the synchronous API.
import faceit
# 1. Initialize
data = faceit.SyncDataResource()
# 2. Fetch a player
player = data.players.get("nickname")
# 3. Get paginated match stats
matches = data.players.all_matches_stats(player.id, faceit.GameID.CS2)
# 4. Use ItemPage utilities
positive_kd = matches.filter(lambda m: m.kd_ratio >= 1)
print(f"Positive K/D Matches: {len(positive_kd)}")
Sources: README.md:40-71, src/faceit/api/data/players.py:165-175
Data Access and Pagination
The library provides two modes for data access: Model and Raw.
| Mode | Property Example | Return Type | Description |
|---|---|---|---|
| Model | data.players | Player / ItemPage | Parsed Pydantic models with type safety. |
| Raw | data.raw_players | dict / list | Unprocessed JSON response from the API. |
Sources: src/faceit/api/data/init.py:60-115, src/faceit/api/base.py:133-176
The ItemPage Collection
Paginated responses in Model mode return an ItemPage. This collection provides functional utilities for data manipulation.
.filter(predicate): Returns a new page with items matching the condition..map(func): Transforms items using the provided function..find(attr, value): Locates the first item matching the attribute criteria..get_random(): Returns a random item from the page.
Sources: src/faceit/models/item_page.py:75-125
Pagination Iterators
For large datasets, use the all_ prefix methods (e.g., all_history) or explicit iterators to handle multi-page fetching automatically.
This sequence illustrates how PageIterators automate the fetching of multiple data pages.
Sources: src/faceit/api/pagination.py:270-350, src/faceit/api/data/players.py:255-275
Error Handling
The library raises specific exceptions derived from FaceitError.
| Exception | HTTP Status | Description |
|---|---|---|
BadRequestError | 400 | Invalid parameters or pagination request. |
UnauthorizedError | 401 | Missing or invalid API key. |
NotFoundError | 404 | Resource (player, match, etc.) does not exist. |
TooManyRequestsError | 429 | Rate limit exceeded. |
APIError | Other | General wrapper for unexpected API responses. |
Sources: src/faceit/init.py:28-40, src/faceit/http/client.py:145-163