A Python library for retrieving and filtering chess puzzles from the Lichess database.
Project description
ChessPuzzleKit
ChessPuzzleKit is a Python library for accessing and working with nearly 5 million chess puzzles from the Lichess puzzle database. It provides functionality to retrieve unique puzzles by theme types, rating, popularity, and more, all with zero setup.
Features
- Filter puzzles by:
- Theme (e.g.
fork,pin,mateIn2, etc.) - Rating or popularity range
- Other attributes
- Theme (e.g.
- Automatically downloads and caches a Lichess puzzle database (almost 5 million puzzles, ~900 MB)
- Supports custom PostgreSQL or SQLite database connections
Installation
You can install this package from PyPI:
pip install ChessPuzzleKit
Usage
import chesspuzzlekit as cpk
# Initializes an SQLite database if none provided
cpk.initialize_connection()
# Optional: use custom database path or connection string
cpk.initialize_connection('/path/to/database')
# Get puzzles and optionally filter
puzzles = cpk.get_puzzle(themes=['fork'], ratingRange=[2000, 2200], count=3)
for p in puzzles:
print(p['fen'], p['moves'], p['rating'])
# Retrieve all possible themes
themes = cpk.get_all_themes()
print(themes)
# Close any database connections
cpk.close_all_connections()
Supported Puzzle Themes
attackingF2F7 queensideAttack kingsideAttack middlegame
quietMove advancedPawn promotion underPromotion
enPassant interference deflection intermezzo
clearance attraction discoveredAttack xRayAttack
skewer fork pin doubleCheck
sacrifice trappedPiece hangingPiece defensiveMove
equality endgame pawnEndgame rookEndgame
bishopEndgame knightEndgame queenEndgame queenRookEndgame
capturingDefender zugzwang mateIn1 mateIn2
mateIn3 mateIn4 mateIn5 mate
backRankMate smotheredMate bodenMate anastasiaMate
doubleBishopMate arabianMate hookMate killBoxMate
vukovicMate dovetailMate exposedKing crushing
veryLong long short oneMove
master superGM masterVsMaster advantage
opening castling
Available Puzzle Attributes
| Attribute | Description (editable) |
|---|---|
GameUrl |
Link to the full Lichess game |
FEN |
Board state in Forsyth–Edwards Notation |
Moves |
Solution moves for the puzzle |
OpeningTags |
Opening tags or names |
PuzzleId |
Unique identifier for the puzzle |
NbPlays |
Number of times the puzzle has been played |
Popularity |
Popularity score of the puzzle (-89 to 100) |
Rating |
Difficulty rating of the puzzle (339 to 3352) |
RatingDeviation |
Uncertainty in the puzzle's rating |
Themes |
List of themes (e.g., fork, pin, mateIn2) |
Contributions
Bug reports, bug fixes, documentation improvements, enhancements, and ideas are all welcome - please submit an issue or start a discussion in this repository. For anything else, please send inquiries to breezechess99@gmail.com.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chesspuzzlekit-1.3.0.tar.gz.
File metadata
- Download URL: chesspuzzlekit-1.3.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24affb872db3e097001f8fd3b130942fa89efae558a37fcc415f0e8ead5f45ae
|
|
| MD5 |
3194cdfbf245ca025e88309918583090
|
|
| BLAKE2b-256 |
77d8a6c3d3c307c00df80744d7cf2b92ef1dfcdf2650756bd1528bcc950fa8a6
|
File details
Details for the file chesspuzzlekit-1.3.0-py3-none-any.whl.
File metadata
- Download URL: chesspuzzlekit-1.3.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00f5edc61a83d6a8f71238b4479bac988b11225df36c817b68c0697dc97eb9e4
|
|
| MD5 |
9585d7af9c306c28ca44980386ea202c
|
|
| BLAKE2b-256 |
eca84175b4a3401c843774c1294243ad354feca3a754476b60078ba8f6a23d2d
|