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.20.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.20.1
File Actions
cython_extensions_sc2-0.20.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for cython_extensions_sc2-0.20.1-cp313-cp313-win_amd64.whl
cython_extensions_sc2-0.20.1-cp313-cp313-win32.whl CPython 3.13 CPython 3.13 Windows x86-32 Details for cython_extensions_sc2-0.20.1-cp313-cp313-win32.whl
cython_extensions_sc2-0.20.1-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details for cython_extensions_sc2-0.20.1-cp313-cp313-musllinux_1_2_x86_64.whl
cython_extensions_sc2-0.20.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 for cython_extensions_sc2-0.20.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
cython_extensions_sc2-0.20.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for cython_extensions_sc2-0.20.1-cp313-cp313-macosx_11_0_arm64.whl
cython_extensions_sc2-0.20.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for cython_extensions_sc2-0.20.1-cp312-cp312-win_amd64.whl
cython_extensions_sc2-0.20.1-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details for cython_extensions_sc2-0.20.1-cp312-cp312-win32.whl
cython_extensions_sc2-0.20.1-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details for cython_extensions_sc2-0.20.1-cp312-cp312-musllinux_1_2_x86_64.whl
cython_extensions_sc2-0.20.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 for cython_extensions_sc2-0.20.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
cython_extensions_sc2-0.20.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for cython_extensions_sc2-0.20.1-cp312-cp312-macosx_11_0_arm64.whl
cython_extensions_sc2-0.20.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cython_extensions_sc2-0.20.1-cp311-cp311-win_amd64.whl
cython_extensions_sc2-0.20.1-cp311-cp311-win32.whl CPython 3.11 CPython 3.11 Windows x86-32 Details for cython_extensions_sc2-0.20.1-cp311-cp311-win32.whl
cython_extensions_sc2-0.20.1-cp311-cp311-musllinux_1_2_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ x86-64 Details for cython_extensions_sc2-0.20.1-cp311-cp311-musllinux_1_2_x86_64.whl
cython_extensions_sc2-0.20.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.17+ x86-64, Linux glibc 2.28+ x86-64 Details for cython_extensions_sc2-0.20.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
cython_extensions_sc2-0.20.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for cython_extensions_sc2-0.20.1-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 44.9 MB

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

Download URL cython_extensions_sc2-0.20.1-cp313-cp313-win_amd64.whl
Size 727.5 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
bb2fa32ebe6eb5635aceb098cec557b456e91e6fcefb87250f9137bc42c1c1a2
BLAKE2b-256 checksum
How to use checksums
cb8534251b2cef52b06ca52d93066e29bb5439af449e4746eaea8bb75126a04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp313-cp313-win32.whl
Size 578.6 kB
Tags CPython 3.13 Windows x86-32
SHA-256 checksum
How to use checksums
968b5d4aeac354830e73bf9fe69caf28e98434de9517468b64190ab19c65e0b0
BLAKE2b-256 checksum
How to use checksums
3984292341ff794d001a86488b805a90bcce65de30fb24c59f003a854551e2f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp313-cp313-musllinux_1_2_x86_64.whl
Size 6.3 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
6c6485468ecaa42eb31422f847fa1a0df06dca35d315188ab69cb5f2778d362a
BLAKE2b-256 checksum
How to use checksums
e022bb0cef28b9c06c2592b134032c4c839417882ac3a590f906fd6a8ce43f16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 6.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
80b9923860fc15b6050078d40a152fd9ef80673f13965b156cc00cdbb2bd6726
BLAKE2b-256 checksum
How to use checksums
e92aa2a28efbbf031a4722c50300cede60ebdbdc445975d4cf4c864c9a006604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp313-cp313-macosx_11_0_arm64.whl
Size 915.6 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9ef5c7afe139da68e9096b9a9f715a6bb74262aea1530dc228b46b6f1b05a40f
BLAKE2b-256 checksum
How to use checksums
c336707652a7761461c28919f35dc0aff7886796b5b5e24cda5da06472896fd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp312-cp312-win_amd64.whl
Size 733.8 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
911d150dcbbbfa7ce2491f539e0e1c881762fdc70e87530f18b05649163ec235
BLAKE2b-256 checksum
How to use checksums
82a8fa29ef95e82bf4116e67cbd17e8988b58cff84dc976b75c66ae400ecb101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp312-cp312-win32.whl
Size 580.5 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
b68ebb2159da5bece300400231ed4919db434c7ebe9e1fce9c0789f3fe3d9d7b
BLAKE2b-256 checksum
How to use checksums
c606a816291d9538747cefe47800ec5de19fe46aaac127cac16135fb6b3baea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp312-cp312-musllinux_1_2_x86_64.whl
Size 6.4 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
5b142135464f4e56bc5caf6ee636bdc6948acc8614e76b82a8242091ffb3efa6
BLAKE2b-256 checksum
How to use checksums
e97404351f3753e82aaf9f6fce48485410c0ab41c0b4d2cac81ff4246da8cd22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 6.4 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
88ef2173706409e74b02b9793aa76874bbbcdfe76f66eae82254948ff4ec5118
BLAKE2b-256 checksum
How to use checksums
a645833e577f36ee4c92c4aca7ec6713155d8f5d89f61124cc861a540dd491f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp312-cp312-macosx_11_0_arm64.whl
Size 914.4 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
19fe345eed6e1677d5e7a730b43aa1d4f501d47ac3d930dfb5171fc6e0c6e89b
BLAKE2b-256 checksum
How to use checksums
0b3b879791f1a7f4678236df70869b36d7175f627f91cfe6f6132f90c411a700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp311-cp311-win_amd64.whl
Size 756.4 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
9efbab5019bbb44f32367d12e3d1595c308ec449f1339496f56807096f4d9c69
BLAKE2b-256 checksum
How to use checksums
72f6786c981f1f89301d586fc8722da1416e8d6ecf4679037b8125a583999c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp311-cp311-win32.whl
Size 598.2 kB
Tags CPython 3.11 Windows x86-32
SHA-256 checksum
How to use checksums
ac420e202b271c511c6bf892176d3972a67455089219352473075cf3c347f04e
BLAKE2b-256 checksum
How to use checksums
b650db2a8d74191eeddbe724742c39eb667702859ac596d37512aceda6b13496
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-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
5eb59aa535e2cbe89622dcbc6d6a7c8ee7db4785243d3836a45969d7813dd219
BLAKE2b-256 checksum
How to use checksums
79a0e77f6251f9c0255f24c1491e36a126bafbb7756ea32c10b62e1a597d6824
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-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
82128bbb250db429c853f1d3b609b944cf0a625431f6b3d7592b30a48544ed20
BLAKE2b-256 checksum
How to use checksums
2e3292fac26de4b0008b01f6b58f5363314c65f7a75fd902e080f26b7e2be34f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

Download URL cython_extensions_sc2-0.20.1-cp311-cp311-macosx_11_0_arm64.whl
Size 921.8 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ebb06fbe7a6bab13da23f6ac2dab8ac2c90e031df9623d66c53be2f777cd5007
BLAKE2b-256 checksum
How to use checksums
bfec32ce27482595349c839d7c2aeb6fa2480bcb9c2178497d2b6d15fe18e909
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for cython-extensions-sc2 0.20.1

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.

Release history Release notifications | RSS feed

This release

0.20.1 This release

15 release files No provenance

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