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

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.17.0
File
cython_extensions_sc2-0.17.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
cython_extensions_sc2-0.17.0-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details
cython_extensions_sc2-0.17.0-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.17.0-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.17.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
cython_extensions_sc2-0.17.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
cython_extensions_sc2-0.17.0-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
cython_extensions_sc2-0.17.0-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.17.0-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.17.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
cython_extensions_sc2-0.17.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
cython_extensions_sc2-0.17.0-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details
cython_extensions_sc2-0.17.0-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.17.0-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.17+ x86-64, Linux glibc 2.28+ x86-64 Details
cython_extensions_sc2-0.17.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details

Total release size: 44.2 MB

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

Download URL cython_extensions_sc2-0.17.0-cp313-cp313-win_amd64.whl
Size 726.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
99fdcb70bc978b97db1afe45f0b128d9ff3c2e8c372a33e93973881643cceff9
BLAKE2b-256 checksum
How to use checksums
371d0b612b2117dbb9e26b646b7ca2997a27e8de4e3ca74b698fab4443cc1357
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.17.0-cp313-cp313-win32.whl

Download URL cython_extensions_sc2-0.17.0-cp313-cp313-win32.whl
Size 563.1 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
47e1e657bb38658b94c6745d0f094a943b0794109867c46d0b0ddfb5df363826
BLAKE2b-256 checksum
How to use checksums
b21d70c27d3e04cf26803c0f52e8fbd9b742b9c7881b12a42ede95a85a1c32c5
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.17.0-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp313-cp313-musllinux_1_2_x86_64.whl
Size 6.2 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
95b61b92188c8259e4b7089ccb882b95e435a629c588fab2777aae7fd44b3385
BLAKE2b-256 checksum
How to use checksums
783745c41b6b95ab88a3af257be283016c34b8a3caac6570061ae07d6414e017
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.17.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 6.2 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
be805d01b9c370069017b8feed4005309af20c397102e3492dc26d0a8bd8a5c8
BLAKE2b-256 checksum
How to use checksums
c774276f8e9009f5c5ed4ee1c12769a35fdd1e8f55ad6cdd969047e6635f1af4
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.17.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.17.0-cp313-cp313-macosx_11_0_arm64.whl
Size 819.3 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f4a3c1357a85f59dc6cb4bae97d4582b6eb9ccd6f1870730319b80146a16bc75
BLAKE2b-256 checksum
How to use checksums
156f360b3f029a4302277d96f0f1f1a8c53844166645e9899d05245c37c10e4b
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.17.0-cp312-cp312-win_amd64.whl

Download URL cython_extensions_sc2-0.17.0-cp312-cp312-win_amd64.whl
Size 731.9 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
777bc32fb8d35562d7d2c84d48cdb0939d40d0e25549e4555b0acbb9dfb2d633
BLAKE2b-256 checksum
How to use checksums
23809d7a28fdd75f9370df447c0c11e4935ddd825b1ea93a76bc44ebc7a0c893
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.17.0-cp312-cp312-win32.whl

Download URL cython_extensions_sc2-0.17.0-cp312-cp312-win32.whl
Size 565.0 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
f851ffd5ad1cb078ba9456cac821ac780ea9e4f20635b66be4fdc59c41f3a53b
BLAKE2b-256 checksum
How to use checksums
ff01f27db61e0802e0787275b81f8388ae87f92cc8275dcd1edbf7e504c06a7b
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.17.0-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp312-cp312-musllinux_1_2_x86_64.whl
Size 6.3 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
024a40f1924ba4e286a775cfa05d65d1a514cab3613ec1ca851fbb3d01553cec
BLAKE2b-256 checksum
How to use checksums
11b8bae3fb0eca952fc77c8916474db3d7502a2a9e931494d7670aa3d147da58
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.17.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 6.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
06a9873d117ad80d2f4911d193ae1b74bc58f29fdbca87546dd68418ec115fc5
BLAKE2b-256 checksum
How to use checksums
c7a863c6c5d75251b31316d4213a05bc82b414fdf050a9972ee0e58995598a4b
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.17.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.17.0-cp312-cp312-macosx_11_0_arm64.whl
Size 823.9 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
724744d8eaee3bc9d42d6384092a562698295aa93a07c826fc6e2b786c41685b
BLAKE2b-256 checksum
How to use checksums
db72cf831e9b6838617af9c6d284eb0fc4f711ac489e5377573e832b4bab3386
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.17.0-cp311-cp311-win_amd64.whl

Download URL cython_extensions_sc2-0.17.0-cp311-cp311-win_amd64.whl
Size 747.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
d6e466df9088e1de87be4c0b78611a886d44eeaf24a4a38b1bd94cfd0f18dba7
BLAKE2b-256 checksum
How to use checksums
b6cb5bc508acc220d97b91bef1039949b1df03744ff18cbb5f791369a0b7649a
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.17.0-cp311-cp311-win32.whl

Download URL cython_extensions_sc2-0.17.0-cp311-cp311-win32.whl
Size 580.7 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
0068ecef5ceb71f0676498ccc01c716024aeb5f814b35cfcbb521e6f0e0fab32
BLAKE2b-256 checksum
How to use checksums
5b3edaa767313a2686598f8d8712e4b9805bbc24fe57fa49ba8793094c39dfa1
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.17.0-cp311-cp311-musllinux_1_2_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp311-cp311-musllinux_1_2_x86_64.whl
Size 6.4 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
8d31aec613c29e4a282d334c8c98630b48b114cacae6f2ef8dc21c0dc2204a90
BLAKE2b-256 checksum
How to use checksums
4b6363bcc9e2d159bf3e2eb9de61971d67b8f38f76e0a058173611f82d322e69
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.17.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL cython_extensions_sc2-0.17.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 6.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
50284632f8867d4e5617ec122a60eed1e9820f9d56ff67444622103b8a8af716
BLAKE2b-256 checksum
How to use checksums
1c9ac9141500e9c1ef428044b6aab8a0e1815472a85c1ace9838ca82f47b71cf
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.17.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL cython_extensions_sc2-0.17.0-cp311-cp311-macosx_11_0_arm64.whl
Size 846.6 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c2c172d00e59f063ff5233b1205e1b81c1befbd19a7d816b359f70f179ef8ffc
BLAKE2b-256 checksum
How to use checksums
8db50b719725329a8ebc6c5e8c55469bb21604e42dbaa36a945580a08aa5c87e
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