Skip to main content

Async wrapper for the faceit API for csgo

Project description

Async faceit API

Async wrapper for the faceit API for csgo.

Here are the docs

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')

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_faceit_api-0.1.3.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

async_faceit_api-0.1.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file async_faceit_api-0.1.3.tar.gz.

File metadata

  • Download URL: async_faceit_api-0.1.3.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for async_faceit_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 843dbb0e1e3323c57745ed6f33d35ccae386efbe715b289edc8c654c1abea53d
MD5 f71ac29468b458e5faa354de53a6fe38
BLAKE2b-256 06de2bf2c5f77403893c09b1dafc07d9c8decd19fa2f782e3836c96e86c60c47

See more details on using hashes here.

File details

Details for the file async_faceit_api-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for async_faceit_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d03b158b59e753a31a27b6c6df061d3e8ca58f92bc301b6d7c07e519eebe1770
MD5 f4cb94a853ff3962385e3ddc7bf1196a
BLAKE2b-256 a9f963cf7a1db3e2d7e08e9f155478e8ff29dec7fd86f5a252179d45a1013f1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page