chessvision ♟️
A fast, lightweight chess board and piece recognition toolkit.
Install
# With uv (recommended)
uv tool install chessvision
# With pipx
pipx install chessvision
# As a library
uv add chessvision
# or
pip install chessvision
Usage
CLI
# Predict chess positions from a board, screenshot, or book page
chessvision board chessboard.png
# Predict a single square image
chessvision square square.png
Python API
from chessvision import (
BoardDetector,
BoardPredictor,
Castling,
Orientation,
PieceClassifier,
Turn,
)
# 1. Full Board Recognition
predictor = BoardPredictor()
prediction = predictor.predict(
"chessboard.png",
orientation=Orientation.WHITE,
active_color=Turn.WHITE,
castling=Castling.ALL,
)
print(prediction.render_board)
print(f"FEN: {prediction.fen}")
print(f"Confidence: {prediction.confidence:.2%}")
print(f"URL: {prediction.url}")
# 2. Multi-Board Detection
detector = BoardDetector()
boards = detector.detect("page.png") # Returns list of cropped PIL Images
for board in boards:
prediction = predictor.predict(board)
print(prediction.fen)
# 3. Single Square Classification
classifier = PieceClassifier()
square_prediction = classifier.predict_square("square.png")
print(f"{square_prediction.label} [{square_prediction.confidence:.2%}]")
# 4. Batch Squares Classification
batch_predictions = classifier.predict_squares(["e4.png", "e5.png"])
for prediction in batch_predictions:
print(f"{prediction.label} [{prediction.confidence:.2%}]")
CLI Subcommands
chessvision board
| Flag | Short | Default | Description |
|---|---|---|---|
--orientation |
-o |
white |
Board perspective (white or black). |
--turn |
-t |
white |
Side to move (white or black). |
--castling |
-c |
- |
Castling availability (see castling options). |
--open |
False |
Open position directly in Lichess editor. |
Castling Options
| Value | Description |
|---|---|
- |
No castling for both sides (default) |
KQkq |
Both sides can castle both sides |
KQ |
White can castle both sides |
kq |
Black can castle both sides |
K |
White can castle kingside only |
Q |
White can castle queenside only |
k |
Black can castle kingside only |
q |
Black can castle queenside only |
# Specify board perspective (white or black orientation)
chessvision board chessboard.png --orientation black
chessvision board chessboard.png -o black
# Specify castling availability
chessvision board chessboard.png --castling KQkq
chessvision board chessboard.png -c KQ
# Specify side to move (white or black)
chessvision board chessboard.png --turn black
chessvision board chessboard.png -t black
# Open position directly in Lichess editor
chessvision board chessboard.png --open
chessvision square
# Predict piece on a square image
chessvision square square.png
Model & Cache Management
chessvision automatically downloads the pre-trained ONNX piece classifier (chess_piece_classifier.onnx) from Hugging Face on its first run and caches it locally:
Default File Paths
| OS | Cache Path |
|---|---|
| Linux | ~/.cache/chessvision/chess_piece_classifier.onnx |
| macOS | ~/Library/Caches/chessvision/chess_piece_classifier.onnx |
| Windows | %LOCALAPPDATA%\chessvision\Cache\chess_piece_classifier.onnx |
Attributions
Training assets were extracted, and preprocessed from Lichess open-source piece sets and board themes (see their COPYING.md for individual asset licenses).
License
This project is licensed under the MIT License.
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 chessvision-0.4.0.tar.gz.
File metadata
- Download URL: chessvision-0.4.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fc450a0be138e12b491c66cc8b683404b7e70aa3ee40c03f23013578559f6ab
|
|
| MD5 |
f07a78f9252fda2507b9e6c8f88e916a
|
|
| BLAKE2b-256 |
d9933cbc81d80afbc3414699a90122d9148a3c16fcc0b1f5c15f3e66afdfd43a
|
File details
Details for the file chessvision-0.4.0-py3-none-any.whl.
File metadata
- Download URL: chessvision-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b60ab946194e2a456e42931e00f6dca0cc06135d6524b81367ff861a988178
|
|
| MD5 |
ee6d4b22a9ddd7e71e933a7b54e7521f
|
|
| BLAKE2b-256 |
f4f9e6085bd77cd740f5dc5eb968a6ae29a0a17781e644e0c24cd7c994ae8682
|