Skip to main content

Testing Deploy Documentation

cython-extensions-sc2

API Documentation - for a full list of included functions.

cython-extensions-sc2 is a library designed for the python-sc2 API. Its purpose is to offer optimized Cython alternatives for commonly used functions, along with additional useful custom functions.

Note: This library is included for ares-sc2 users by default, no further setup is required.

This library also supports python-sc2 and sharpy-sc2 bots, see Getting Started below.

Example speedups, results may vary depending on machine and exact scenario. This is by no means a list of all functionality offered.

python-sc2 function cython speedup
units.closest_to 6.85 - 13x speedup depending on scenario
distance_to 3 to 7x speedup depending on scenario
position.center 2x speedup
already_pending for units 6.62x speedup
already_pending for structures 4x speedup
units.in_attack_range 2.05x speedup
units.sorted_by_distance_to 8.62x speedup
unit.is_facing 9.1x speedup
Point2.towards 14.29x speedup
has_creep 4 - 5x speedup
in_pathing_grid 4 - 5x speedup
closer_than 12x speedup
further_than 12x speedup

Tip: use cy_distance_to_squared where possible for extra 1.3x speedup.

Getting started

To quickly get up and running locally (for python versions 3.11, 3.12), install cython-extensions-sc2 with:

pip install cython-extensions-sc2

Type Safety

cython-extensions-sc2 includes type safety checking to prevent your bot failing with silent errors. This is disabled by default for pure performance reasons, to enable it call enable_safe_mode(True).

from cython_extensions import enable_safe_mode
# immediately after importing any cython functions
enable_safe_mode(True)

Even with safe mode disabled, there will still be some function overhead, but it should be negligible. However, if you want to squeeze every last bit of performance out of your bot, you can import cython functions directly from the cython files to avoid using the type checker functionality all together.

Example using cy_closest_to turning off safe mode for some performance:

from cython_extensions import cy_closest_to, enable_safe_mode
enable_safe_mode(False)

You could instead import cy_closest_to directly:

from cython_extensions.units_utils import cy_closest_to

Shipping to ladder

When shipping to ladder, grab ubuntu-latest_python3.12.zip from releases in this repo and extract cython_extensions directory within the zip to the root of your bot's directory, like so:

MyBot
└───cython_extensions
│   └───cython-extensions library files
└───your bot files and directories

Alternative local setup

If you already have a python-sc2, or sharpy-sc2 development environment setup, then cython-extensions should work out the box with your bot without the need to install extra requirements. Simply check out the releases on this repo and download the correct zip for your system.

release

For example a Windows user should download windows-latest_python3.12.zip.

Inside this zip you will find a cython_extensions directory, this should be placed in your bot's root directory like so:

MyBot
└───cython_extensions
│   └───cython-extensions library files
└───your bot files and directories

Start using cython-extensions-sc2

For ease of use all cython functions are importable via the main module, for example:

from cython_extensions import cy_distance_to, cy_attack_ready, cy_closest_to

note: in this project all library functions have a cy_ prefix to prevent confusion with python alternatives.

Contributor / Cloning the project

Install poetry if you do not already have it installed.

Then to setup a full development environment run: poetry install --with dev,test,docs,semver

This will set up a new environment, install all required dependencies and compile the cython code for your system.

If you modify the cython code, run poetry build to compile it.

Jupyter Notebooks

Run poetry run jupyter notebook to open jupyter notebook in the environment. See the notebooks directory for examples. Use template_notebook.ipynb as a starting point for your own notebooks.

Updating ids

ability_mapping.pyx ids are generated via a script, these should be updated after a new SC2 version is released. Run poetry run python scripts/update_ability_mapping to update the ids.

Run Test Bot

Edit the map in bot_test.py and run with: poetry run python tests/bot_test.py

Contributing

Contributors are very welcome! There are many missing alternative python-sc2 functions, and if you're into optimization, the existing functions could likely be improved.

Adding new functions

If you want to add a new function, please add it to the relevant '.pyx' and '.pyi' files. See existing functions for examples. Please also add tests for your function in the tests directory.

Additionally, the new function should be added to the type checking system in cython_extensions/type_checking First add a validation function inside cython_extensions/type_checking/validators.py using the existing examples as guidance.

Then add a safe_wrapper function inside cython_extensions/type_checking/safe_wrappers.py using the existing examples as an example. Ensure your new function is exported at the bottom of this file. Preferably check the new function works in a real bot before submitting a PR. You can use tests/bot_test.py to test your function.`

Commit messages

Please use conventional commits if you choose to contribute, it helps the automatic releases detect a new version and generates an accurate changelog.

Example git messages:

feat: add new cython function

fix: fixed buggy function

test: add new test

ci: update github workflow

docs: add new docs

chore: add dependency

Metadata

Release files for cython-extensions-sc2 0.16.1

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

Built distributions (wheels)

Table of built distributions (wheels) for cython-extensions-sc2 0.16.1
File
cython_extensions_sc2-0.16.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
cython_extensions_sc2-0.16.1-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
cython_extensions_sc2-0.16.1-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
cython_extensions_sc2-0.16.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
cython_extensions_sc2-0.16.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
cython_extensions_sc2-0.16.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
cython_extensions_sc2-0.16.1-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
cython_extensions_sc2-0.16.1-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
cython_extensions_sc2-0.16.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
cython_extensions_sc2-0.16.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
cython_extensions_sc2-0.16.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
cython_extensions_sc2-0.16.1-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
cython_extensions_sc2-0.16.1-cp311-cp311-musllinux_1_2_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ x86-64 Details
cython_extensions_sc2-0.16.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
cython_extensions_sc2-0.16.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 32.8 MB

Release files / cython_extensions_sc2-0.16.1-cp313-cp313-win_amd64.whl

Download URL cython_extensions_sc2-0.16.1-cp313-cp313-win_amd64.whl
Size 540.6 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
5dcc110ee8463e095a6f6a542336a33ac658ff4d449d6b718c88bf8682b75d24
BLAKE2b-256 checksum
How to use checksums
af818622f4bb36cb5b13f8da19e6a8a1fa103ac65560d42239e834cca356b2f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp313-cp313-win32.whl

Download URL cython_extensions_sc2-0.16.1-cp313-cp313-win32.whl
Size 416.5 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
ef6ce6cb384ec791d4f8d43d04f7ca8b1f12d0df1119c015d0b95d37b26006ef
BLAKE2b-256 checksum
How to use checksums
c2b54dc73c5fa41cec3bc0b837ecd5d7a3727f394e6eef4abdc8dfa40ff73b06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp313-cp313-musllinux_1_2_x86_64.whl
Size 4.6 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
041937cf40b57d25f5cdc282721b03f17deabf458f79173a1ba2f287e791ee95
BLAKE2b-256 checksum
How to use checksums
c9f4a541880e9a446f4271d67bb2d8bede4b76a60380e39074abf120a1cbdf82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 4.6 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4a9c2e840b25881e0ef9ef3f931c88a939a81358262f670071fa71a3793ad212
BLAKE2b-256 checksum
How to use checksums
54a50f71e48445538dc338c5e483610a69ae2beb589d8d9ba3875f8cf5742e63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.16.1-cp313-cp313-macosx_11_0_arm64.whl
Size 613.2 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
53372aeea48e34fffaaa81c3c05a021c316a1d23067752b83efd1d6eb6f0cc3f
BLAKE2b-256 checksum
How to use checksums
bf70085f6465947733d614fce92b71cbef616c6088eaf649f30e810286fb680e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp312-cp312-win_amd64.whl

Download URL cython_extensions_sc2-0.16.1-cp312-cp312-win_amd64.whl
Size 545.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
51e0dfae7b6f1358fc0fdcfa660906e3860d3baf3c252e71b7fc4d30ccc5aca1
BLAKE2b-256 checksum
How to use checksums
7fe048e4a9e57591751c19bda00cce07042884a0cd75e7b13f09a796670336d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp312-cp312-win32.whl

Download URL cython_extensions_sc2-0.16.1-cp312-cp312-win32.whl
Size 417.8 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
42b9ad4ee4f86ad4805ba031d55b25ba8714df6da316b4be86b5536afe285ebf
BLAKE2b-256 checksum
How to use checksums
d3344be194dd5e302cb2bfdf3ac2260723288fee230f7941e88f3a82172d0e22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp312-cp312-musllinux_1_2_x86_64.whl
Size 4.7 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
6edd688d84b6e6183aa824f4f3667e11f83a8ea8601bf8077fc59fbd0ededbcb
BLAKE2b-256 checksum
How to use checksums
698106b32e938d76dbfc8d0a8853e08972316ab418212a6adb7e4042cd0de4a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 4.7 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6a54a13c3a6927186b9315b630c2f6d3124039a6f6a20d245a7d2388285d1822
BLAKE2b-256 checksum
How to use checksums
0a5795bdf125f7d46f2fe17c5e640a6f2edf52c7782ba26d64d5fc0ec6b6cf64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.16.1-cp312-cp312-macosx_11_0_arm64.whl
Size 620.3 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8ffc39cae8c831c777d9ddde794fd548f2e9d2d844106d950e0ea5a218241844
BLAKE2b-256 checksum
How to use checksums
b8cdb7eebe59f8c1d16a5d0e65b308dd9a300791a52f86102cc088d888a4a670
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp311-cp311-win_amd64.whl

Download URL cython_extensions_sc2-0.16.1-cp311-cp311-win_amd64.whl
Size 553.7 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
446671b2b3c953a100b07d043630bf823733f9859dd02abb8b7367be6022a91e
BLAKE2b-256 checksum
How to use checksums
80a723e89576d944ef2ba01b21a02b1c65927a5e335107cc04444cbf369379ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp311-cp311-win32.whl

Download URL cython_extensions_sc2-0.16.1-cp311-cp311-win32.whl
Size 429.3 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
19510dcbf965c7972d2d435cfc37343706726b194db1f5a5dee9378d237b4f71
BLAKE2b-256 checksum
How to use checksums
5fb133cef8922f53ec5ecb2c254ad5648d5362a5271f8f206c832ad7bcc87d5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp311-cp311-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp311-cp311-musllinux_1_2_x86_64.whl
Size 4.7 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
3271d120caa7c8ad9028179310771e3df9104596489c8bfc42ffae6962c97b3c
BLAKE2b-256 checksum
How to use checksums
6bb3461b7d39ad305430a6fc03e08952e29c71a9d1dac682207aa3cb8420ec0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.16.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 4.7 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
81148fd98fc500c86f2a25c7322dacdd1a4af6d56baf92a7ac483aa67472ba4f
BLAKE2b-256 checksum
How to use checksums
df834fa73b4d2cda42e2ae1119d2c67079abf29a6a31d8758dac6c107569eae4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / cython_extensions_sc2-0.16.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.16.1-cp311-cp311-macosx_11_0_arm64.whl
Size 633.9 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
01774f603f3fdb622f32f2569f6ae0f048cf5192ee091bc58354b4aa7db46795
BLAKE2b-256 checksum
How to use checksums
6c76b0c7f20a3fba3c37f6cbb15f9b8d4e41dbf88d22e112bb9a7c1d1d3074ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14
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