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.
Metadata
Release files for chessvision 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chessvision-0.5.0.tar.gz | 7.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chessvision-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / chessvision-0.5.0.tar.gz
| Download URL | chessvision-0.5.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9eece4538cca4661c6b71856778a641c50ff609e29ab21122bf0e152716a8ac9
|
|
BLAKE2b-256 checksum How to use checksums |
9caa5987cd11221b20d1b7bbc6157fe58076621c7ae7867344e1e9d8e29026f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / chessvision-0.5.0-py3-none-any.whl
| Download URL | chessvision-0.5.0-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb3815f9773e06b334dcfc70cd703da98e4cc1839fd9692de874c0ef6bb25f8d
|
|
BLAKE2b-256 checksum How to use checksums |
f020481b561a1db2f9b0d129e67996383d24e90da49aa071fad4fc3c8f50efa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|