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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.14.0-cp313-cp313-win32.whl (415.3 kB view details)

Uploaded CPython 3.13Windows x86

cython_extensions_sc2-0.14.0-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.14.0-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.14.0-cp313-cp313-macosx_11_0_arm64.whl (601.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cython_extensions_sc2-0.14.0-cp312-cp312-win_amd64.whl (495.6 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.14.0-cp312-cp312-win32.whl (416.9 kB view details)

Uploaded CPython 3.12Windows x86

cython_extensions_sc2-0.14.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.14.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.14.0-cp312-cp312-macosx_11_0_arm64.whl (610.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.14.0-cp311-cp311-win_amd64.whl (508.6 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.14.0-cp311-cp311-win32.whl (428.3 kB view details)

Uploaded CPython 3.11Windows x86

cython_extensions_sc2-0.14.0-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.14.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.14.0-cp311-cp311-macosx_11_0_arm64.whl (623.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 de2b1ba646a4c6267267d39ae175e6e1f61848f0e9efa53d5a227bb958b01579
MD5 067f498d4b04f10f39a9a870b84ddc2b
BLAKE2b-256 46c7516808b92d3a905ab75c4c8b5a815a77fb4e7f9920112674b38f9a75dcb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 3c090e420aebae8ea4900e9fd0240cbebcf2594d121cc44a097d8fb543cc212c
MD5 0487d9c8d28c7392d9780c5dd7e772b5
BLAKE2b-256 21c59c0720cfa5c0ddf467ddf0286d175f3fbb0bdaaf23f34cbbe20bc34b3eed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 020fe50a882e0ba860909171427022cf72af6ead34e014af60017af1a491d8e0
MD5 e8ce3075041a29a9c1154146f14a66d1
BLAKE2b-256 742426c1874516489e8a745b5b2f149774e01fcd860010cb54798d100d470724

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.14.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.14.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a7453dd98e27b7ef6bfbddbf72c2c1cfef7e52f5ba5dc886a5779adbf647edd
MD5 8ab68c53b4b099e352ad943cee990282
BLAKE2b-256 df39a65d1cef5c45e255ba0356341c39156d1e483166586bddca69191e12e6ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 972b93a35c89152a748f21398f5caad3386deb7aa5b6f20e9b4ab7eaace1c74e
MD5 c6793e782b58aa005cc5c2a0bc5974e9
BLAKE2b-256 e542c67ae44216c66cbbc11a9e2f354c43ce8b4dba2ba508941054392051349a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aa7319868838f59cc67c712c5641dd7d82d7297522188d597a5d0267319c4e43
MD5 147363de8970c3b3ecc9c1371c346aa0
BLAKE2b-256 0bd8431e7f198702f5b8ea03129cd01875ab98e19215cdf33dd886dc73048972

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 800e7d932b9c13b73603bbea95ecfd6742f3dafa4c0f26d828e8917357303acd
MD5 ae5cf216c22674bcd50fc508c6b0a2dc
BLAKE2b-256 4398e85b988dc90c5ad3f7e80a1644c793764d3994d4f66ee2230ef08e6a07e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd2fadd3a787967415510077b618b33eaaca9af2aed3e040b3a20391ce2144d0
MD5 5aa40d957d36444a9880f6d6e9af07d7
BLAKE2b-256 1f490dfb49365d13ec5a4150bee02003017a99537b1cae0661cb059c0ed820ce

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.14.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.14.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7155b0eb1095e491c0b64f3ce570c8655d5b0b7e6bbfb7ce65be10f38f55a538
MD5 a5f95bacc2df3f9d5aa9175ad5b1bf06
BLAKE2b-256 213df8eb4a0a0c49c802d2203590b0c606d79264e33f491c78e40e6533a7bea0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cc6851cdc7ded177b0de13fb3269f79a2f9f15e208901ef5cd161ee0b237b3c
MD5 c33b492e4002ff7fcd26adcb34256337
BLAKE2b-256 3264b2d91619e2ad669f119a463241df6494807123793b4167ed3856eac74815

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c80ca57b3315422a7bb23d9652399f02b08da327edc1d0907f8774d48d19f1ee
MD5 a6ca7529577852c9d1c384a6b86d6397
BLAKE2b-256 26ab11681d92ba2060960d30d109ca3209c34a01cf9a027e0fcad20c09a049e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 6ab9fcf1119e9fb2876eeac664ee8ca7291b96f888188e39d666cc46e5eb2dba
MD5 ccd8299ae7c0481fa803300920d40e97
BLAKE2b-256 2dab254ec5e66ab9fac417146a0bd5e0f4ce23cbacc6d950dda0b5abbb328982

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7d4dbfb2d089d19a0e255e8485d3a8dc4815ea94a549650087506f8c505a35d1
MD5 903ee13a35ca02757a687d1a3ea4d08a
BLAKE2b-256 796125add61867cf12cf47fc5fe5748147252c276bee770a2433fc07112128eb

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.14.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.14.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a0cd02423f1df9b6d1f9fc5d1d8bd703f5f889e4c92b35ee31d45dd161f1facc
MD5 23c9bf28e91625983fc16a8fa83def18
BLAKE2b-256 2499448e3ec4f315bfe7c97c79e3bfd5abd68902996f2009c04dadbcaf5c9114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.14.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3243e6d15ba75a5f98b5dc22b82ca78f1a88ad7c542442e5eb8f40a48a93d65a
MD5 36098b2b43f2a681a321b0250edc71d4
BLAKE2b-256 38ffd3205eb8b8dd84783751f3ad16805e8b0f5a5a7feb073dff26b13e1e14b5

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