← all repositories
thomasahle/sunfish

A 131-line Python engine that beats most humans at chess

Sunfish is a minimalist Python chess engine built to show how much competitive strength fits in a readable, single-file codebase.

3.3k stars Python Domain Apps
sunfish
Not currently ranked — collecting fresh signals.
star history

What it does

Sunfish is a complete chess engine written in Python that implements the UCI protocol and plays at over 2000 Elo on Lichess. It handles all standard chess rules except the 50-move draw rule, and ships with both a terminal interface and a compressed executable under 3KB. The codebase is deliberately tiny—131 lines once comments and whitespace are stripped—making it a self-contained reference implementation rather than a framework.

The interesting bit

The project treats extreme brevity as a feature, not a constraint: the entire packed engine is smaller than many JSON configuration files, yet it still runs an MTD-bi search with piece-square-table evaluation and an experimental 1207-byte NNUE variant. That small surface area makes it a popular sandbox for testing parallel search algorithms, swapping evaluation functions, or grafting on deep learning experiments without wading through tens of thousands of lines of C++.

Key highlights

  • Plays above 2000 rating on Lichess despite fitting in 131 lines of Python.
  • Packs into a 2953-byte compressed shell script that speaks standard UCI.
  • Uses the MTD-bi (C*) search algorithm and classic engine tricks, but relies on standard Python collections for clarity.
  • Experimental NNUE version adds positional understanding with a neural network under 1.3KB.
  • Runs significantly stronger under PyPy—about 250 ELO above CPython at fast time controls, according to the author’s testing.

Caveats

  • Does not implement the 50-move draw rule.
  • The evaluation function is deliberately primitive: piece-square tables only, with no midgame/endgame distinction.
  • NNUE mode trades positional awareness for tactical weakness because the implementation is not yet fast enough.

Verdict

Grab this if you want a readable, hackable chess engine for experimentation or teaching; avoid it if you need a production-grade rules engine or a tactical monster to analyze your blitz games.

Frequently asked

What is thomasahle/sunfish?
Sunfish is a minimalist Python chess engine built to show how much competitive strength fits in a readable, single-file codebase.
Is sunfish open source?
Yes — thomasahle/sunfish is an open-source project tracked on heatdrop.
What language is sunfish written in?
thomasahle/sunfish is primarily written in Python.
How popular is sunfish?
thomasahle/sunfish has 3.3k stars on GitHub.
Where can I find sunfish?
thomasahle/sunfish is on GitHub at https://github.com/thomasahle/sunfish.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.