Skip to main content

chessvision ♟️

CI codecov Hugging Face python

uv ruff ty pytest

A fast, lightweight chess board and piece recognition toolkit.

chessvision demo


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"Valid: {prediction.is_valid}")
if not prediction.is_valid:
    print(f"Errors: {prediction.validation_errors}")
print(f"URL: {prediction.url}")

# Access the chess.Board object directly
board = prediction.board

# 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.name} [{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.name} [{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

square prediction demo


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.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chessvision 0.6.0
File Size Uploaded
chessvision-0.6.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chessvision 0.6.0
File Interpreter ABI Platform
chessvision-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.2 kB

Release files / chessvision-0.6.0.tar.gz

Download URL chessvision-0.6.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ca17344859279dfd7f800d702de0e45e08224e72600d8a7aa4cc17bcd8596044
BLAKE2b-256 checksum
How to use checksums
ef249ba97360d5e3a88b71b8322ad4dd3373ce25d79e676dc43009ed11f2f273
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.6.0-py3-none-any.whl

Download URL chessvision-0.6.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23fe3bbea1280af90d7fe4e0e409abbaed4fb08c3e89ba88fc6c65d6fabb28de
BLAKE2b-256 checksum
How to use checksums
cca842159ee36e4c1791c8e271090983da580f71cd0005b96e98d0be35316891
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 history Release notifications | RSS feed

0.12.1

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page