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.13.5-cp313-cp313-win_amd64.whl (492.0 kB view details)

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.13.5-cp313-cp313-win32.whl (413.3 kB view details)

Uploaded CPython 3.13Windows x86

cython_extensions_sc2-0.13.5-cp313-cp313-musllinux_1_2_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.13.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.5 MB view details)

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

cython_extensions_sc2-0.13.5-cp313-cp313-macosx_11_0_arm64.whl (599.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cython_extensions_sc2-0.13.5-cp312-cp312-win_amd64.whl (493.4 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.13.5-cp312-cp312-win32.whl (414.9 kB view details)

Uploaded CPython 3.12Windows x86

cython_extensions_sc2-0.13.5-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.13.5-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.13.5-cp312-cp312-macosx_11_0_arm64.whl (608.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.13.5-cp311-cp311-win_amd64.whl (506.1 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.13.5-cp311-cp311-win32.whl (426.3 kB view details)

Uploaded CPython 3.11Windows x86

cython_extensions_sc2-0.13.5-cp311-cp311-musllinux_1_2_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.13.5-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.13.5-cp311-cp311-macosx_11_0_arm64.whl (620.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4b70d7a61b13c95a0b740bc991f981d552f6b6d3ccdb168eb4964a1971e62e58
MD5 311942ef3b8b1a0db0f26fc0b84ca401
BLAKE2b-256 2350724c6013d4345f5ce6413bad52d9954e9e11cdbfb5dcfc2eebe6d1c98c9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 b501a9b7d295fd834950ffe4024b48467aa79498cecdde8ff8d3bacd153fc197
MD5 2ac126f4e071445709b9a7d029b89f43
BLAKE2b-256 2dd93f149b57da4ff6f931826a7f4f6f17076e70714ef2265f090998a9d07e14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d87dd1b2939dabc2a99cbc6d5bab11ca5562b17ae3fdc04991cbf6fb2db905bd
MD5 11392d86eef4c7b9254b21de03cbdb1b
BLAKE2b-256 098706e56b01222c19e93b2d72195e5020cd75e2ef9ff780cf972e00b710b5f8

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.5-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.13.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c993453d5bae50635e423e30e6a046f7a1f7d26dd3de1bd6054c68763651aa7
MD5 58fe359830dcc098a60f7ccfc515b791
BLAKE2b-256 7221d976c134b5065319da2b80a8d6ee255da6ae37b22e978d6ae56c2249890e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4bfeb832cd8a4758041845195cb5ff5a04f30883bfb736d445babae9cdba18d
MD5 7cc8e08eaa576cef482e01c721158347
BLAKE2b-256 81b58194390f19ac9136371d0d6456cec9161ffc45d5b19b3cf1f99b20dba6fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 26c7782cec424c7387f9c351d9b82e75836d5fb74e2ed5fa71f1f9e010535dab
MD5 be69c40939946cc5fdaac4aa3da84872
BLAKE2b-256 e96a299103176c5c12e16fd8d231e3f33969a407b3de45a558e13bbf2c849bf8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 b83f90b0a22458a1d81f290539ae7323ecd1df591a45c814f0a1503a992bd0bd
MD5 c37e0905126bd5a2b7f359872d8b1143
BLAKE2b-256 eeb4b2ff0daaeae4fe73f1e324f67966a1c5cbfaa544dea9bde599b17ee8631c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 41d9c9bd8cd269e640b3834de770f2255cabc783e07ada192d624bbae1577ede
MD5 e7014f78eed4b5e0ffc8a3822298d3ff
BLAKE2b-256 4ee42fe7e71f052ff6e6e89f88198f7afa8698c94bbb99172a4cd35608d407f2

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.5-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.13.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97aa084c508cd99154b5fd2c6940605276885ab8e7707417300f17a200b2239e
MD5 b620ba415099c684057fd53f39861a98
BLAKE2b-256 817cc6e9e9280b2ea5b3a88c3d999b61ad484d158a3d43c25793e9c22fde4967

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c9a79c937c95bca01a41b07ff478a18c407eee94cd44187314ba1762f4857d9
MD5 5aaa6169a9015911ef469f062ebe95b3
BLAKE2b-256 7632c0a251bb692728690dd0129f6c1ec4fe837b57d8c3e275e550e5df8d4fa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d537a66449b1c844a6ffaa003fad7a3846e7ee5fd11b77543122a10173c0b0de
MD5 573ca5735acbae9f64a0a70c192dcd89
BLAKE2b-256 ec1c54450405a039545c25798b6103eb4671e9d782ccedf273d3115258cd598b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 bd6f3017b1c1be4e7515d621f6cd95062f4fbd3f36991b2c5f4c6434748bb5ca
MD5 80d78afeb09fbd365029f5a1ef632c92
BLAKE2b-256 a0cd7332018b03fd22f35670ca2c588ef5d975f74481c809b93607d082a1eb44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ca292440759cd4883e06d9c5f396b02e6710afc218d9fbceaa4e3d668ef6cb09
MD5 2f1007f1992fdfcfd5c9ed47e1ac7567
BLAKE2b-256 a3b5c407d5ded4134941db8c12cd5b3fe0e66b017e7d7fd0c14ae27ddc778f3f

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.13.5-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.13.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cc58ab64a19b6dac7c3ed9d9f96c4442f0dffa18926e1c6a72e0489daf7250da
MD5 138d898eb78532b4a5e8016d661a5a35
BLAKE2b-256 8c36a73a029af5a17fe871e59f602e956621211041a3929d5d1befacd14cbdf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.13.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95b55e9f89e44bbefff4f46cc99fce3d7f68ae5711206351706f2c3b728f08d3
MD5 f5753430644f2d3449fd3fa4f8319061
BLAKE2b-256 754e60e01ad75fa69a263808aff9a2e2021c418ee2a3af2bdc77465e18832759

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