Skip to main content

No project description provided

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cython_extensions_sc2-0.16.0-cp313-cp313-win_amd64.whl (496.8 kB view details)

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.16.0-cp313-cp313-win32.whl (417.8 kB view details)

Uploaded CPython 3.13Windows x86

cython_extensions_sc2-0.16.0-cp313-cp313-musllinux_1_2_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.16.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.16.0-cp313-cp313-macosx_11_0_arm64.whl (605.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cython_extensions_sc2-0.16.0-cp312-cp312-win_amd64.whl (498.1 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.16.0-cp312-cp312-win32.whl (419.8 kB view details)

Uploaded CPython 3.12Windows x86

cython_extensions_sc2-0.16.0-cp312-cp312-musllinux_1_2_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.16.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.16.0-cp312-cp312-macosx_11_0_arm64.whl (614.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.16.0-cp311-cp311-win_amd64.whl (512.6 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.16.0-cp311-cp311-win32.whl (431.3 kB view details)

Uploaded CPython 3.11Windows x86

cython_extensions_sc2-0.16.0-cp311-cp311-musllinux_1_2_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.16.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

cython_extensions_sc2-0.16.0-cp311-cp311-macosx_11_0_arm64.whl (627.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file cython_extensions_sc2-0.16.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b01cb4e1ecf64ad8c22432acacc2b0396834377de00a9534a51732044cc86276
MD5 81e5986721bed36c7a7ef46113f9739b
BLAKE2b-256 1ff4317ab754f67a963a92d68867fa32a8f2d54b4a968f2ff082dff771dfe98d

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp313-cp313-win32.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 b1c5551e8d5efe3763582a122d02601de9de9ccb42bb87dde2d46fbb160dbb38
MD5 41f8157b5db3ac89110f09dfac855af1
BLAKE2b-256 eb7a84958d27874cfc044d6acac9bc688b2caccf7a555a1be2c0418d4ec4ec0b

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 79472743eb38bedde0f8dbcff53487d451e92dace4b5a29c9a3eb738f7ad1e3c
MD5 233de08cd0297329b33c30e264fbd4d3
BLAKE2b-256 6a42607be63033bef159b92617ce0fd2d8f93ab912a22ed119b27b87d40f36a4

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bca049592b13a87fbbb0949b85ade720ff0bd86bf6880bf12a2eaea070ccecb1
MD5 bba31f9e291b6f454cf50ae5736ade6b
BLAKE2b-256 d5b4e2f26011d40467b2060a3fc9a94cee02516faa6aee6ab9e170ce7c0dd72a

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de19dd264ee8557941bc4652d26cd543ba1ee39cb8ccdfc1f673fcc4736ae4ea
MD5 39489f7b567348e14e329e66b3fa406e
BLAKE2b-256 26d84db14ad228e10191b3702fe76d51f2f79d74c06fa81995e3a184e32cc121

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8fccae8274c39c961b26185dcdda4b109f58fe5fef9737c1459e0e295b3f29ce
MD5 7591700e6227028c24961a05ae21498c
BLAKE2b-256 6c108c3bb32e0e428d6519283eb13c32d075ea76f8d902c4531203c1d9c1cae4

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 bcb2520a368ac0e364e1ab398b34cac11ec1cd9442f7363a4232a79f4c09d0b8
MD5 fcef83a98de64108007691d907102a1a
BLAKE2b-256 ad8e24f225aa723eb7a56b615caa91c8b3c94d515e9519bd7002fc633a3c719c

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f6b94f114a6e9bcf5a21acc98530abda45c6c521db5424997319f4b52db5a19d
MD5 7751eae755e2b769a7a34950a5cc1dd4
BLAKE2b-256 b58a43c54944e213b4d9858bf0d61e361c0e4e0be8e8877359244a7b2b62e60f

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a7216777d7bfe1dfead259748d5220cfc709932c7c0dfdc015bb8fad610ed99a
MD5 62e92d0ac10d8859cf5e000d359c551b
BLAKE2b-256 cc187f91db1c15c9ca91ce3bffb98751b97207b3e3e639dfe85f301d047199c2

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e041f52d549f7c0c8b41a7d94b959ad36127c4f0fe17df69438aee17242d6a7a
MD5 4592796936e64542c2780459b43c8a51
BLAKE2b-256 7331302ed25e24d4912cb0c241447812d7f2d3a073de2765934d6306ccaa3c52

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ba596066a5e187eeff2d433f3516a455d24cf248308c87a812b8f5896bedc34e
MD5 7927f46eb91c9758bec1b536de868d1c
BLAKE2b-256 ecf2140fc29f774077e4b3b2175fa4a6d4bf19f98239d398139b8235f9dd0164

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 e164cc5fbdff651baadcc3fe6aa9c6ada9d788bbdd15f6db98689760dc2b56af
MD5 b3c0fb85260bc378c50d17bc901c3088
BLAKE2b-256 a42886e91d9c9f5101155079ab7e11e4f016c5c70424769643d1b6851975e4df

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0036f34e0c6d12357c990dec3a5e78627625ec1d3001af91d80eb3c9884f509d
MD5 7e663d69e3f526a3e5f796e4f547ecbf
BLAKE2b-256 0f7aec817b534a5bfbb10e616d2df796b973bd6cb3cca118e53d4beec5e9c9b6

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 be70b509ff88d65aa5252c81fdcaadde1de2cd7b5d8c8dc316e21cd6a225dbba
MD5 9ed97b8e468c2d2c30911a63b02ef165
BLAKE2b-256 5f776858f50a2c80ab4d32d69103a681d974fc8d0e7b811b0e93cf4417efa53d

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.16.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.16.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ed19765dde07a675f226f16384a468fe8d0cbfda2a015a0d598ef7138a2755f
MD5 7872a474ae59b3686942626202b5b209
BLAKE2b-256 7ad6779c74f486f1c2a4a0b469a12056d31f468ac79fa0ad9e2a4a56c49ae1fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page