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

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.10, 3.11, 3.12, 3.13), 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 enabled by default, but for a bit more performance you can disable it.

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

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

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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.8.12-cp313-cp313-musllinux_1_2_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.8.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

cython_extensions_sc2-0.8.12-cp312-cp312-win_amd64.whl (423.8 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.8.12-cp312-cp312-musllinux_1_2_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.8.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

cython_extensions_sc2-0.8.12-cp312-cp312-macosx_11_0_arm64.whl (564.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.8.12-cp312-cp312-macosx_10_13_x86_64.whl (602.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

cython_extensions_sc2-0.8.12-cp311-cp311-win_amd64.whl (432.7 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.8.12-cp311-cp311-musllinux_1_2_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.8.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (3.9 MB view details)

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

cython_extensions_sc2-0.8.12-cp311-cp311-macosx_11_0_arm64.whl (569.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cython_extensions_sc2-0.8.12-cp311-cp311-macosx_10_9_x86_64.whl (619.4 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9f06c44d6eafba872a9bc6efdeb591b6d430208abfb2ca05c1cd51bb5e811e34
MD5 32b492ecefb32df2dc1cd1a907720356
BLAKE2b-256 8d032ec9aab9a51c8e05cd710bba01f45d16da909b7773d1e9e28aaa035f1a44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e9b8601f20f75ba67e8943aac2812d03817d271c4c8280dcb2b82d97e34e346d
MD5 5172554d155ddd3e4c7e7c2952a179e2
BLAKE2b-256 2615e99914af63071bfacd135e56d60f5af5758181af7ea30c8641839b225cff

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.8.12-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.8.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 94003e6f9c4db2cf5e7a440a502aeb0e05c13d08ca90e721534d2745920c389b
MD5 975048c399cc91bcc3f55507a4ae4a01
BLAKE2b-256 7c4844808d1756090a218fa1bdf4cec893bd1c21f2a51a0c8b67cb27b5bb23b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 84af1d84fd89e453bb3819097796242436926fb9ef2ede0fe90eb94880b3e190
MD5 a8875f05b34315b48f38508b9795e506
BLAKE2b-256 e810c657695e79ae8fb1821c4f572160ece0d09f3e1b80cd5cadc089c6c3ffb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ad6e872b9e816a04834e4f9496c6a7eafeebbc8bd51d64718834918e4e068291
MD5 2d12d2dc4f867c3343c2e010437eb888
BLAKE2b-256 3c9470d4d0c6afd1fff335e9db938853221c1f2f413d35353b084639c1016f27

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.8.12-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.8.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce18c5e56c70b7f52deb4fa17aed77cab71b36458d4a8d477a32b8e487ed31cc
MD5 1435fa816bcc8a9f70ded4196207fd12
BLAKE2b-256 1e4b671e7ead373aac7014130e5d59ec19ceb0b477fafd0895c7c00033849f35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f88be5a9d241dbea37708e8d5f4219da534700ac7fdd9f5d4fba7298853437d8
MD5 1fc213c25bd94f09c9303d10b8b77d69
BLAKE2b-256 020a0a577a5002302e090e3790bdf03f657268a4e0dca7dd335c0f5e0de7fc2c

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.8.12-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4382da940816815f51bbb79cec7923c54df2125c343fd5dc2253e96d5afaeb50
MD5 8b88a590e599126eb402a26e4e1cc7f0
BLAKE2b-256 ae3ff03e180c58fbfee9eceb207ff838f104948e95097d566cd19f947a3a32f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ec0fa652f143188601398179959fd17925e377ab95bd7086a6a162059ed7240c
MD5 1e2160e573444f1f685320442b2c12e5
BLAKE2b-256 dc6d0086478e5ef5c1746a0febdda19f828066c35ccb23b56e5ebf4042be13d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 25d9d48fdf10d7fbfaaceba5df188cbf99be7babfa4afdebe386b90bdc7d1318
MD5 76ca905681cc948f33ab337a1d3ae0f6
BLAKE2b-256 5829f57d7bad106211342a5c30973a15b9e03fb79a99b2cd26764d37e33a1c21

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.8.12-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.8.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ea8ea940dddf14004d08fa8b4398a47c12e51fe02db50a9abb2f349dbcd79ee
MD5 12f26294df479ef8015de0b9b6d74228
BLAKE2b-256 55cedd71e58b15258e65784bd98725e77739390ef682a56e28d78e3824c2c746

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d836fc454ecbe2d87d3e1ad61095d1a7ddabf4cf695de9cc3872ac0a8ccc5bfa
MD5 1c537a30318b399efec06fffe620ae25
BLAKE2b-256 65f23466e03987fed5f1cae9f8ee84ef7d09fc0250e428de34ec3223617668e8

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.8.12-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for cython_extensions_sc2-0.8.12-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6adfa8e3df8992a88f0beef32e33bed8273df56ecb0de365e47213702e8a54bf
MD5 21578726ee64b4329b193da7aaf422a8
BLAKE2b-256 ad957ea6d0f4c9575f383c6ad8bf0ce2b769a2e461023c3269b093e9efbb6234

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