About This Project
This project is a heavily optimized Cython version of python-chess. It implements the same move generation functionality but with
performance improvements using Cython and C++. Since python-chess is licensed under GPL v3,
this project is also licensed under GPL v3.
Cython is a programming language that serves as a bridge between Python and C/C++. It allows you to
write Python-like code that can be compiled into highly efficient C/C++ code. This makes it an ideal
tool when you want to optimize the performance of certain Python programs while still leveraging the
simplicity of Python. Cython also allows you to invoke custom C++ code to further boost speed by bypassing
Python alltogether. In this project, I rewrote functions pertaining to move generation from the
python-chess using Cython and C++. I use Cython to interact with Python objects from python-chess such as
chess.Board or chess.Move objects but try to seperate code that involves bitmask parsing and other such
operations into a C++ file for even more speed.
I may in the future look to optimize other portions of the python-chess library but as it stands,
the overhead of calling Cython functions for small functions such as is_capture seem to be more costly
than simply calling the same functions from python-chess. Move generation however is somewhat lengthy and therefore
the Cythonized code (as well as the C++ injections) can give around a 40% improvement in move generation.
Note: This project includes C++ components and therefore requires the ability to compile C++ as well as Python. When pip installing the package, the required Python components come with it but you need to ensure you have the ability to compile the C++ files. To do this ensure you follow the build requirements below.
Build Requirements
Ensure you have Python 3.8 or greater installed on your system along with an udpated version of pip. When installing this package, all required Python dependencies will be installed alongside it. To ensure full functionality, confirm that you have a C++ compiler installed. If not, use the following instructions to download one.
Windows
- Download and install Microsoft Visual C++ Build Tools 2022 or later from:
https://visualstudio.microsoft.com/visual-cpp-build-tools/ - Ensure you select the C++ CMake tools for Windows and MSVC compiler during installation.
- To verify you have correctly installed the C++ compiler run this in the Developer Command Prompt (not the regular command prompt):
cl
- Note that simply installing MSVC build tools may not initialize your system properly. You may have to set environment variables or update your path with the cl.exe compiler.
Linux
- Install the necessary C++ compiler and build tools:
- For Ubuntu:
sudo apt update && sudo apt install build-essential
- For Fedora:
sudo dnf install gcc-c++ make
- To verify you have correctly installed the C++ compiler run this in a terminal:
g++ --version
For MacOS
-
Install Apple's command-line developer tools (includes clang for C++):
xcode-select --install -
To verify you have correctly installed the C++ compiler run this in a terminal:
g++ --version
Download
To download this package, use the following instructions:
- For Linux:
pip install cython-chess
- for Windows (Not yet published on PYPI):
pip install git+https://github.com/Ranuja01/cython-chess.git
Example Usage:
To use the module, simply import cython-chess as seen below:
import cython_chess
The module will self initialize, allowing you to use it automatically.
Since this module currently only improves the move generation speed, it still relies on the board objects from the original python-chess
library. The following example demonstrates how to use the python-chess board object for move generation while utilizing the optimized
cython-chess library to speed up the process. The start and end squares for move generation are defined using bitmasks from the original
python-chess library:
import cython_chess
import chess
board = chess.Board()
cython_chess.generate_legal_moves(board,chess.BB_ALL,chess.BB_ALL)
The following code can be found in the example usage file. Run this script to test the speed improvements. Note: You may need to pip install timeit if not already done so for this
from timeit import default_timer as timer
import cython_chess
import chess
board = chess.Board()
## SPEED COMPARISON
t0= timer()
for i in range (100000):
for move in board.generate_legal_moves():
pass
t1 = timer()
print("Time elapsed: ", t1 - t0)
t0= timer()
for i in range (100000):
for move in cython_chess.generate_legal_moves(board,chess.BB_ALL,chess.BB_ALL):
pass
t1 = timer()
print("Time elapsed: ", t1 - t0)
Metadata
Release files for cython-chess 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cython_chess-0.3.tar.gz | 111.0 kB | Without provenance | Details for cython_chess-0.3.tar.gz |
Built distributions (wheels)
Total release size: 23.9 MB
Release files / cython_chess-0.3.tar.gz
| Download URL | cython_chess-0.3.tar.gz |
|---|---|
| Size | 111.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e2343cb7664f173ca19c9aba6d21164517cfc42c24f8f4cdfcf91a9d936a44b
|
|
BLAKE2b-256 checksum How to use checksums |
87b17d88f46bc87d426daab41c36fa1c41a88f629d7905ab65e46855df2d6232
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | cython_chess-0.3-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
57e9edfe5ef81728d8bbe6d56def326f1166ee0245e1b71d3ad86f0a1555a43a
|
|
BLAKE2b-256 checksum How to use checksums |
38281ebc436fb81eb439a300c0026c68da12f575cf9bf22067750df69f771e76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp312-cp312-musllinux_1_2_i686.whl
| Download URL | cython_chess-0.3-cp312-cp312-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
1763f51540e6741b9ed5daba600c2dd2ccd7a7d4280d50a316218097e14e9dc0
|
|
BLAKE2b-256 checksum How to use checksums |
ef83c3c67c16be2358b18df461dacf3754af641048748f7a3d5cf81866316eff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cython_chess-0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 637.6 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
1cb49a057d5331a7d3eb4677c994476c960ffe8400c7839da697b9008d7710e5
|
|
BLAKE2b-256 checksum How to use checksums |
b129c3eb99db1a02b71390e6cfc04c8092fd2ced2125bce51566443613932265
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | cython_chess-0.3-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 617.8 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
1e1bef055229c1291453264b942214a8b23d3faa1e218307b312e4809a04d173
|
|
BLAKE2b-256 checksum How to use checksums |
a23539e119323f435f8999067c7729f48907b7db6e7dfb8ec3dbcbf32a15ba2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | cython_chess-0.3-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
741c7e5dabb7f9107133f44dc46414de90ecde0f5384daa630e194071e9bdaa9
|
|
BLAKE2b-256 checksum How to use checksums |
8f814c4e7f16065dab69b8f744cedb80484d1b9dfd93744a3df60da28ef8a961
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp311-cp311-musllinux_1_2_i686.whl
| Download URL | cython_chess-0.3-cp311-cp311-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
0d9f428c1b9c1de14c7fa56b4de27f3994707f5434249e60dd343c505389d65c
|
|
BLAKE2b-256 checksum How to use checksums |
cc599f0475248808a1d167114f7758b08d5d53a92cd9abe2fae6d27d44b12afb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cython_chess-0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 635.0 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c82288df95e1c9fb4d58e2f7a294daf12c0a7bd5f3e525d7bdab811f87692617
|
|
BLAKE2b-256 checksum How to use checksums |
fcc47d1adc3507620d6332bef9f9e4d74b3b2fc2b5dc549a0c3b9765c23889c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | cython_chess-0.3-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 624.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
2eebb652850e8d54e56d2d900253f1d6a3da62bed857a1489e4a845c1598c7f3
|
|
BLAKE2b-256 checksum How to use checksums |
ad3eb96429f82d7748bb1ad183ad4a0831c4c1701a7be867db2a5a0ff07bf601
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | cython_chess-0.3-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
5346a210e81d3e37b97b49221d1afa73580e61e66a503ae35bd78478daa013a8
|
|
BLAKE2b-256 checksum How to use checksums |
479fa22ccaa2369e78743781725291ed63d8b1d509d02a16f27d9fe0e7e12088
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp310-cp310-musllinux_1_2_i686.whl
| Download URL | cython_chess-0.3-cp310-cp310-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
23dd6560a0b5ae5e184519391b409e0079a0008495bdd349e2a59ea3dafcd43d
|
|
BLAKE2b-256 checksum How to use checksums |
2c4def29f6a046ef5b1cf4410b8c78eacfeb6dbfdd506607f7bbc109faf7d6e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cython_chess-0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 616.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e96f06f1b64011409256c2562f85e22e8d3f1434e839c3a0e1204bfb26854203
|
|
BLAKE2b-256 checksum How to use checksums |
1d9c1fc767583496295289dc7463dba57a3e159fa97483bd575aff78c3e33d57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | cython_chess-0.3-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 610.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
8abbaa23709a9cdbe46c0620dcf06aab9b9323ca8335107cecdb4cd7ef4e3cdf
|
|
BLAKE2b-256 checksum How to use checksums |
bf7ce6cae53e49fda5e378568c6be0c21a26d67c38969202cc7570fc3db75167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp39-cp39-musllinux_1_2_x86_64.whl
| Download URL | cython_chess-0.3-cp39-cp39-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
ccdbd3f561151323ff8eab11a2748760ff2d0b417b74c10f7478af8a9e4727e2
|
|
BLAKE2b-256 checksum How to use checksums |
48f9ffa6487da96e64bc28e954e03baa2a933ce6bca0fb1f1ff068f9283e5b63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp39-cp39-musllinux_1_2_i686.whl
| Download URL | cython_chess-0.3-cp39-cp39-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
0d8899f113a7a723bae8cc8b79d0e3da60d9ce14e5246079c0846cab4fdf44bf
|
|
BLAKE2b-256 checksum How to use checksums |
80fb9caffd12a7fbe4e56cb84fa4ecfcf1b2541a052599985cd7e0c32a6f2d00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cython_chess-0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 616.7 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
06fef0fbd105872a803cb34053fcc4431328b0e66946dd49ae0dfc6bc1ec2a83
|
|
BLAKE2b-256 checksum How to use checksums |
268353caaa40884f7eef359d7e39c46d830364dfb11928701651af8b71bf1cd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | cython_chess-0.3-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 608.0 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
370b202a1f88a7f3ad539dbe159dae25e8c81a0bd954fde10b9c71993f9450ba
|
|
BLAKE2b-256 checksum How to use checksums |
24eb824b9bb59c20396202891b00954c5fc0fd3df10a0ad8de932b11e5e00cbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp38-cp38-musllinux_1_2_x86_64.whl
| Download URL | cython_chess-0.3-cp38-cp38-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
182910c8ec7d3e14059a9d2affa072e75f8aeb715e0673de53587737930fa94c
|
|
BLAKE2b-256 checksum How to use checksums |
3540fe6322ba741b807eff256a1786b9d8839f664b3c227061d89962a48a9f52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp38-cp38-musllinux_1_2_i686.whl
| Download URL | cython_chess-0.3-cp38-cp38-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
0c5d0ed55e737f49324b2a9626c3e7672fb3eb31ee7669b3478c38ff65d1f6c4
|
|
BLAKE2b-256 checksum How to use checksums |
d08626b9714567360a1728f41153b17be89e1f5004ffedd99cf78e49b83dd150
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | cython_chess-0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 628.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7d4534d286ad899847ef24ce55260a927174f771c37db49cc354a010d1dcc5cf
|
|
BLAKE2b-256 checksum How to use checksums |
256e3f590af8996e17ccf8461e8327b9e62c3cfeb1ba9eb5bcc4a25edba053a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / cython_chess-0.3-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | cython_chess-0.3-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 621.3 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
25122ec49a9da6e6076592287d78c7a45dce026db10308a6a68cd16afee4bcf6
|
|
BLAKE2b-256 checksum How to use checksums |
2c6a4b2c01d6208a1a0d55509be62609519e35985cd14e69cf690f4516dab3f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Security for cython-chess 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.