Skip to main content

Async Python client for the Lichess REST API

Project description

aiolichess

Async Python client for the Lichess REST API.

Installation

pip install aiolichess

Quick Start

import asyncio
from aiolichess import AioLichess

async def main():
    client = AioLichess()
    user = await client.get_all(token="your_pat_here")

    print(user.username)
    print(user.perfs["blitz"].rating)
    print(user.count.win)

    await client.close()

asyncio.run(main())

With an external session

import aiohttp
from aiolichess import AioLichess

async with aiohttp.ClientSession() as session:
    client = AioLichess(session=session)
    user = await client.get_all(token="your_pat_here")

API Reference

AioLichess(session=None)

The main client class.

Parameter Type Description
session aiohttp.ClientSession | None Optional external session. If not provided, one is created internally.

await client.get_all(token)

Fetches all account information for the authenticated user via /api/account.

Parameter Type Description
token str Lichess personal API token

Returns a LichessUser object.


await client.get_user_id(token)

Fetches only the user ID of the authenticated user.

Parameter Type Description
token str Lichess personal API token

Returns a str.

user_id = await client.get_user_id(token="your_pat_here")
print(user_id)  # "drnykterstien"

await client.get_username(token)

Fetches only the username of the authenticated user.

Parameter Type Description
token str Lichess personal API token

Returns a str.

username = await client.get_username(token="your_pat_here")
print(username)  # "DrNykterstein"

await client.get_statistics(token)

Fetches rating and game count statistics across all formats.

Parameter Type Description
token str Lichess personal API token

Returns a LichessStatistics object.

stats = await client.get_statistics(token="your_pat_here")
print(stats.blitz_rating)
print(stats.rapid_games)
print(stats.puzzle_rating)

await client.close()

Closes the session. Only closes if the session was created internally — never closes an externally provided session.


Models

LichessUser

Field Type
id str
username str
url str
created_at int
seen_at int
play_time int
perfs dict[str, LichessPerf]
profile LichessProfile | None
count LichessCount | None

LichessPerf

Field Type
rating int
games int
rd int
prog int
prov bool

LichessProfile

Field Type
flag str | None
location str | None
bio str | None
fide_rating int | None
uscf_rating int | None
ecf_rating int | None

LichessCount

Field Type
all int
rated int
win int
loss int
draw int

LichessStatistics

Field Type
bullet_rating int | None
blitz_rating int | None
rapid_rating int | None
classical_rating int | None
puzzle_rating int | None
correspondence_rating int | None
bullet_games int | None
blitz_games int | None
rapid_games int | None
classical_games int | None
puzzle_games int | None

Exceptions

Exception Raised on
AioLichessError Base exception, catch-all
AuthError 401 — invalid or missing token
RateLimitError 429 — rate limit hit, wait 60s
LichessServerError 5xx — Lichess server error

License

GPL-3.0

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

aiolichess-1.2.0.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

aiolichess-1.2.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file aiolichess-1.2.0.tar.gz.

File metadata

  • Download URL: aiolichess-1.2.0.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiolichess-1.2.0.tar.gz
Algorithm Hash digest
SHA256 04cebe26bce6d1633979d86b7198c0e00c49068aade3509e1bc08eb136c2c480
MD5 1dd21db8f87a6570de15c2f6c7a1fe59
BLAKE2b-256 e5233d2a4eb6946ab17ace3cfa51e9278a448b4d627aa0640a746d50ca2337b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiolichess-1.2.0.tar.gz:

Publisher: publish.yml on aryanhasgithub/aiolichess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiolichess-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: aiolichess-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiolichess-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f41ad284a84a3d6f452c4f51e98c6579a943d247c18dfa5ea2e95872e0e57562
MD5 f6eedc072b653fd4e59646c44e7ea12d
BLAKE2b-256 f4e2ed6ca7619949302e454184f4fcb7d31e1093dd410e4dbebd9dfd953c9e7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiolichess-1.2.0-py3-none-any.whl:

Publisher: publish.yml on aryanhasgithub/aiolichess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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