Installation & Setup
Relevant source files
The following files were used as context for generating this wiki page:
Installation and Setup covers the procedures for adding the faceit-python library to a project and configuring the necessary credentials to interact with the FACEIT Data API. This process ensures the environment meets the Python version requirements and provides the required API keys through manual or automated means.
The library uses a resource-based architecture where users initialize a DataResource (either sync or async) to access specific API endpoints like players, matches, and championships.
Requirements
The library requires a modern Python environment and specific third-party dependencies for HTTP communication and data validation.
- Python Version: Requires Python 3.10 or higher.
- Core Dependencies:
httpx(HTTP client),pydantic(Data models), andtenacity(Retry logic). - Optional Dependencies:
python-decouplefor environment variable management.
Sources: pyproject.toml:13-30, README.md:32
Installation Procedures
You can install the library using the standard Python package manager pip.
Standard Installation
Run the following command to install the core library:
pip install faceit
Sources: README.md:36
Installation with Environment Support
If you plan to use environment variables (e.g., .env files) to store your API key, install the env extra:
pip install faceit[env]
Sources: README.md:42
API Key Configuration
The library requires a valid FACEIT API key to access the Data Resource. You can obtain a key from the FACEIT Developer Portal.
Key Handling Methods
| Method | Implementation | Requirements |
|---|---|---|
| Automatic | Loads from FACEIT_API_KEY environment variable. | faceit[env] or python-decouple |
| Manual | Pass string directly: SyncDataResource("KEY"). | None |
| Custom Variable | Pass FromEnv("VAR_NAME") to the constructor. | faceit[env] |
Sources: README.md:46-51, README.md:79-85, src/faceit/http/client.py:92-94
Validation Logic
The library validates the API key format using a UUID validator before attempting any requests. An invalid key format raises a ValueError during initialization.
Initializing Resources
The library provides two primary interfaces for interacting with the API: SyncDataResource for synchronous code and AsyncDataResource for asynchronous code.
Synchronous Setup
Use SyncDataResource for scripts and standard applications.
import faceit
data = faceit.SyncDataResource(api_key="YOUR_API_KEY")
Sources: src/faceit/api/data/init.py:75-80, README.md:58
Asynchronous Setup
Use AsyncDataResource with async/await for high-concurrency applications.
import faceit
async with faceit.AsyncDataResource() as data:
# Use data here
pass
Sources: src/faceit/api/data/init.py:96-100, tests/test_e2e_data_resource.py:46-48
Technical Architecture Overview
The initialization process constructs a client-resource hierarchy. The DataResource aggregates specific sub-resources (Players, Teams, etc.), which in turn use a shared HTTP Client for requests.
Conclusion
Setting up faceit-python involves installing the package via pip and providing a validated API key. The library supports both direct key injection and environment-based configuration through python-decouple. Once initialized, the DataResource provides a type-safe interface to the FACEIT platform.