Skip to main content

Async faceit API

Async wrapper for the faceit API.

Here are the docs

Getting started

If you dont already have a loop in your programm you need to create one. Here is a basic example which will search players by the username and prints out a dict with the nicknames and player_ids:

import asyncio
from src.async_faceit_api import FaceitAPI


async def my_task():
    api_key = "..."
    api = FaceitAPI(api_key)
    players = await api.search_players("username")
    print({player.nickname: player.player_id for player in players.items})


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    loop.run_until_complete(my_task())
    loop.close()

Its recomended to store the api_key somewhere safe (e.g .env file)! Here is another example on how you can implement the api:

class MyApi(FaceitAPI):
    def __init__(self):
        api_key = os.getenv('faceit_api_key')
        super().__init__(api_key)

    async def get_played_maps_parallel(self, player_id):
        matches = await self.player_history(player_id, Game.CS_GO)
        all_match_stats = await asyncio.gather(*[self.match_stats(match.match_id) for match in matches.items])
        maps = {}
        for match_stat in all_match_stats:
            match_stat: MatchStats
            map = match_stat.rounds[0].round_stats['Map']
            if map in maps:
                maps[map] += 1
            else:
                maps[map] = 1
        return maps


async def my_task():
    api = MyApi()
    player_id = "..."
    print(await api.get_played_maps_parallel(player_id))


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    loop.run_until_complete(my_task())
    loop.close()

Error Handling

Note that the async api methods return an object of type FaceitApiError if the request was not successful. To distinguish between a successful response and an error, you can easily use the object as a boolean expression:

    games = await api.games()
    if games:
        print('success')
    else:
        print('error')

Metadata

Release files for async-faceit-api 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-faceit-api 0.1.7
File Size Uploaded
async_faceit_api-0.1.7.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-faceit-api 0.1.7
File Interpreter ABI Platform
async_faceit_api-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 39.3 kB

Release files / async_faceit_api-0.1.7.tar.gz

Download URL async_faceit_api-0.1.7.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
0494d6debee805b45e43229004aaf08a66053546dbc0dcd947b4d81ac3561528
BLAKE2b-256 checksum
How to use checksums
27f68e89c02b87fec31f593d407504d2a308f5a6f39e76548eaf29ef93614e5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.7

Release files / async_faceit_api-0.1.7-py3-none-any.whl

Download URL async_faceit_api-0.1.7-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
204cea1bd29e9ca4a76ab1567e3349c7fd6de789bf179e4264aef1b0c2b30cbb
BLAKE2b-256 checksum
How to use checksums
ccb1e86985106f6355e3aa76da49c778a740a01fb2707f86819a3b786ed15d6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page