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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.9.0-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.9.0-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.9.0-cp312-cp312-win_amd64.whl (428.8 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.9.0-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.9.0-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.9.0-cp312-cp312-macosx_11_0_arm64.whl (551.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.9.0-cp312-cp312-macosx_10_13_x86_64.whl (592.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

cython_extensions_sc2-0.9.0-cp311-cp311-win_amd64.whl (437.9 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.9.0-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.9.0-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.9.0-cp311-cp311-macosx_11_0_arm64.whl (556.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cython_extensions_sc2-0.9.0-cp311-cp311-macosx_10_9_x86_64.whl (608.3 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b9d4d484d334df619aefea7cd2056d4d16e1eee99bf061464652903454940efe
MD5 82630ff71bb391c2da58cd82b18c3bb0
BLAKE2b-256 1ae89e02aedb6b87282fa9383479f71c87f1d6123631b3e994deec2c1b1dc69b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 def99c40b5f51415f6d090ed780efefbbe6b0a5e68996b76de33e59ddfab4ab1
MD5 6845e0bad6c13388bf4d90cc33f82f1f
BLAKE2b-256 dd97cb51c4c199cba751780538de079fa5047f95025ad6b5216805617f211754

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.9.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.9.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c2f1f56b4d783da84583000166fb07d7c1830ae9dee6801fbb41bfa8051aec7
MD5 db744d6decd6355f4ad6e76e50267498
BLAKE2b-256 c9a6ed0a788135389578dd4559b0e70aff59770a780bcc5dc3939ed5567b178a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 92ce39482e176e0ad05ccd0e291274586501ce8dd4fa9c61e34d46c8a65ca4bf
MD5 1e4eb3ecebfa93819e49e765b57bee1a
BLAKE2b-256 9184bd5652678bcfc1dd35b6562ab436e9f686e1ecacb4038c517a6973c54535

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4a6240797744a3ec2be2a2d2a669a0e4767113519531548b93f40138f85762b
MD5 2a1c4572bef10549a0362eb7a0e4cafc
BLAKE2b-256 502b99b460a32ab366d9ae35324593036c4e209885ff24852f1a0e5ebb570a83

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.9.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.9.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a5c491bd5e6a512689a62b1016c5dab4e7b771e1c55ffc32785cdebcc50415bb
MD5 d373e9f61ed0e5f82082303eaea871e8
BLAKE2b-256 7b356b4d3b617373d5b57f3b508901128c513a551bc62b8d46039c82ab8a9031

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a6cee3f6da8424972f0711467fb15de18e19154c3f32793a13938749befdc54
MD5 6228609aef6b43af1ae2bca54f531660
BLAKE2b-256 e1b73a200da94b18c3d2425870019dc8340d166779926cff89f46b9c820f2211

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 bfb5559a77563a8149ae037022bc2c9eadd30fa0fd07da039bf9e1f831fe9838
MD5 23124a9f0691423a02e027330d9dfe73
BLAKE2b-256 52fccfbd5017e9cc2d934ffbe28d95c8d5cb8deb68a07e38f235ab34996d735f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2b826ab2ae1d701b5a6b6f5de00c625acdde34ac42b0ca6073fa217cecaf3307
MD5 b0244931d9b569e99e8d8312027f63e3
BLAKE2b-256 85738904f49602124950019990e37b20b5aa3d5c67c2d0cc48419cc7a8549e3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6b95e6c307e950cc066b5b494a381c315de3d2bfd22f23c03727ec4a4803c2ec
MD5 abe319dc493b98ed67a003cda7dcde42
BLAKE2b-256 285a58d55daf05da2a78ecbf8cc866b03a8a551d4d5baab08f2abc69f4641e77

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.9.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.9.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f94c0ba38dedbb29b3130182bfe4daa8f3acefdcf74380febfa7a0792ee1b1b4
MD5 80c9bdf5259ab27c9ce6f6058015e900
BLAKE2b-256 32c85dd6aff284f281f8da4037871c5504facfe94b909475284d97f5b3ce9577

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 992dfb8915a7c49b65f3d02b0bab200d5840c207a602176a2ebb06474e833534
MD5 682cbba9cd81a4e4cde3b3f73eb1a40c
BLAKE2b-256 f244bde119ca40afa97f718e1f1453f227025857b5f3078ed916ae5b1e2f03b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.9.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 99427924fdeeda58b0248c2a801e03ab633d08d903d531f0e387a52eb3b7b461
MD5 4a1a19309d01de3f4307e7299d5d3ee4
BLAKE2b-256 b15dfd903f0976c9ee1d5fd0d580c31fcda3349afab4f513fc1ac83c6322f41b

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