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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.15.0-cp313-cp313-win32.whl (417.0 kB view details)

Uploaded CPython 3.13Windows x86

cython_extensions_sc2-0.15.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.15.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.15.0-cp313-cp313-macosx_11_0_arm64.whl (603.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cython_extensions_sc2-0.15.0-cp312-cp312-win_amd64.whl (496.7 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.15.0-cp312-cp312-win32.whl (418.5 kB view details)

Uploaded CPython 3.12Windows x86

cython_extensions_sc2-0.15.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.15.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.15.0-cp312-cp312-macosx_11_0_arm64.whl (612.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.15.0-cp311-cp311-win_amd64.whl (510.4 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.15.0-cp311-cp311-win32.whl (429.8 kB view details)

Uploaded CPython 3.11Windows x86

cython_extensions_sc2-0.15.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.15.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.15.0-cp311-cp311-macosx_11_0_arm64.whl (625.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d0c8374c5a9733f8fa54b9e8e1b10782f4546891c6e7ef86fef00c457fb90a73
MD5 c060a33bdbf1f70ce5d5587db65be2ab
BLAKE2b-256 f0e10e84cda180b70e887a633d3b02b5195ae39ca2f6441662a8d7b77cdf2460

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 1aafae47af12dd696244087e47ac2f529f995346c44e6047f6889820a65b8c69
MD5 46c5e974c2f3095ef3112c46e78b16b1
BLAKE2b-256 a8da539377ffb1ba82bbd81db33a1c7022c03af4fd43712ee4ed8c0e1a5cd0db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4c0ce78693ee3d987e67869b9f7938df11c66a070418a06e5098743bf35ddc1
MD5 3db97758894b82f47ee009aba4988fd1
BLAKE2b-256 42ddebf722a8f896c9261def76121fb8d03f07d66ce73703b72a4e9dc54d737d

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.15.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.15.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f917023a83ca2ef62774f38f4a745355ee45c01b0a54645d307ef939e5df2bb4
MD5 8d40373c54d4b03d6cc79c6a6462cd0f
BLAKE2b-256 a16868c07bfef03dd1ed522f7cbbc7eaefaf2ac7d088bf707c8050546ced18b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b92a7b4e3f3f9e05360c5199958f9fcbffc0f2f4fdc99f01358392d4374bc2a
MD5 76e61f28cc17c20986e6cf5ddac271b6
BLAKE2b-256 f37fd156eb5a56eaef0bff1b8e1543f3b21425d6ce7737c77babf14f4eb59c32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 feaaf02a93b843e50392e19244e0bbc08c38020fefd8b853fdb7090808a2c460
MD5 2139a1dff8951be6f664058ec2fb71a7
BLAKE2b-256 e760857bf2300dcec85c03b18f5d77277106348241ec117e436f42b02c0524f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 00fc1e154d8ea2c651ea8d6f2c7676bb78317601187d607ae6d1792c279488ab
MD5 3e5e9dc0ce4707d613781cf2b7ff921d
BLAKE2b-256 225882998e6b4822c9381160c07824bd6da1604f5b7f23b8bdf9df744d46ec7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 86fb7b7ba9c449372bb7461c842d8ae6c80986ec40aca427d745c609cf1ca9e6
MD5 eac72dfb6baaebbf65179d2272cc9636
BLAKE2b-256 41ea467d37c888ad6e1a30e8019f8c2542058eccab591b457e357160f7df2ad4

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.15.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.15.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecb42d9342929b7eb011c47c6abe5902ebedddf1ae2b4302f9020e689795c594
MD5 e4161bfa2bdfe357fbe07e7507f4f839
BLAKE2b-256 11d97de4aa92dc0ec7dd861c74b1d61961ee43d8063ff85431e02aa23572d638

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ea9bb08d7201c8a9dd71b8d82c3b6193071ba938a50259121cee6f302d78241
MD5 6612561fac67b283ff66659d8c8bf5d4
BLAKE2b-256 ba60692996f249767e83a63ab5ecb039094636dd0cbe0ed4e332b4e4aaf91c4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dd56386904b472c8e2ee2a1308ceb297a993bbaf07966cead3a3380a3dd03615
MD5 16119e72a0c78f726977c302669a1fef
BLAKE2b-256 fab22d1e2551e920bd62a26476d45af0b882c5820be90382d7a3f9521c9f6e36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 112b2986623eb950ec7233dc87c7912444a56d84a8bd7b611de0ea11280424c3
MD5 3e003ba621a94b719c13524d3fd38d30
BLAKE2b-256 d4530d059e183a54c735e21aeb217a0eced6056928ed9fcaa78858578df5e4fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cac61687924d1bffd558007e4c131b31523ab3a79d4d0dbb9464df07c6eb2448
MD5 551ded94eb5ea8f775f48f75d8e131ce
BLAKE2b-256 b2725a810fd4fab01b98e0e9d69c97ec2226eac1076948407cd21a3a29da6fe9

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.15.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.15.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9652d9b6819857f6f80c34829b198f3095d9a15b4f6a21e4fc881cfc5e1ac114
MD5 90e037c1a88794900a93ce6640139a5f
BLAKE2b-256 ec957e5c565bd601231969ce44a170e0a28778301ed0f03f441c501d9d6aaf66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.15.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fa2fa9fee28ea1421b0906b0cef4c3da83c5681c3509d1f064df58b1a215aa8
MD5 2e3e5ce6965b4f551c185416af178cac
BLAKE2b-256 89493f9f2d9d4efab2d1b611751957be5c6a04baa123ea3e228242f6d3ec5c4e

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