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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.11.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.11.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.11.0-cp312-cp312-win_amd64.whl (431.5 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.11.0-cp312-cp312-musllinux_1_2_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.11.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.0 MB view details)

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

cython_extensions_sc2-0.11.0-cp312-cp312-macosx_11_0_arm64.whl (554.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.11.0-cp312-cp312-macosx_10_13_x86_64.whl (595.6 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

cython_extensions_sc2-0.11.0-cp311-cp311-win_amd64.whl (440.9 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.11.0-cp311-cp311-musllinux_1_2_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

cython_extensions_sc2-0.11.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (4.0 MB view details)

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

cython_extensions_sc2-0.11.0-cp311-cp311-macosx_11_0_arm64.whl (558.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cython_extensions_sc2-0.11.0-cp311-cp311-macosx_10_9_x86_64.whl (613.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5e6f66b03f4f5da62abbdfc289e0018afb7abf09e62e794764ce2fba815f67c0
MD5 f5dcd11b395949f59887242ef82d39c2
BLAKE2b-256 b93c5bae9040c1529432717629874d0ded85805aa970c640c594996565411c66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1c0acdbf04790a7b6eadf230748981b565d4d3e8279005699db83ba6192e1e2b
MD5 af1c155d90d3aca101f0984426a3bced
BLAKE2b-256 26a55b2574fb703de166453fa3a01f35d0ca65fa814095e11b47d0213298ad96

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.11.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.11.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ec8c6d4c935fff8ec6dda4d980010f2f1657b163dba90de7f2d543d0d24e9a09
MD5 d897268e740e8f40ea7af82e682a2b10
BLAKE2b-256 464eeae225bbdb7e26ac292c7de3701af458ffb5727b31c0b98700e1e64d7c90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d1ef8dee46d568ef4365aa175bff1c529fdc4537b6d836afa2045ff874cbae49
MD5 c7125fe83a0e3b1ec86b4467c54a7f59
BLAKE2b-256 c22c04940829b721ca51fbaaf149feb91c6ecbb8531e31fed091add48a9771bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d5c8756196303c443678b6cd9c86aef16b91c3a89cd83c0d913f6d12d5805004
MD5 c97c98d081b0efb48162365d272c2d92
BLAKE2b-256 a8f42353f8c97100b588f9d3128a4d146ae5b0882933eb0dcd73cee840afc07c

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.11.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.11.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 613da61aeff34d58fe6fba2c28e8847c2db6dece5e11d74e20a34e5a567be6f7
MD5 c0c274bfcbcf1accf52e423d497ab651
BLAKE2b-256 0bb8367fdfa07d71ed6a6edd50c5e86479d2ff3ab6ed6e7f6e5619a948c3c43a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 43995d055b1bba79652f2197cd7ab35ead4028e434044ffb837f9daa039fc4b1
MD5 9668fbba6062639f6df3d587c4ca9819
BLAKE2b-256 39a78dc5e6b118598e3c38bc9b150a2f8e20936425b055355c0b3ea443bb92da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 265c6eba21583062383ec1446dadff1413870ee7bcd541601d9d3223d8b391c0
MD5 baac4a0c00336e075b5242cb3841c672
BLAKE2b-256 af1c4e27b59e96b450113e26fc2df185b07e145b50414370f24dd8a2ed721b9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9ec138316c4a76745f2b411df9dfc7d3e832c8c740ab89d6e1301c00b8cf4880
MD5 6b8903b52e60351a7617b8f9be75cf18
BLAKE2b-256 4d644c813abc53c05da4ad8a359dc2e1e7173038efa0241aec665ca431f07889

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cecba53fe639f4e9d139d1dad07289cf953a2d4304298c9976fab40d4fd8a113
MD5 85998fbd778c597d859504d16fcf792d
BLAKE2b-256 b01341439d4950a3ad88219082f0c38851f42f03df44b18d7b81d059ff9e6706

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.11.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.11.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 07c0c2eeb7fc8fcb425a714b3a97f576e9c5d81a11b4775290e459de4d326da8
MD5 e56d638a8ebe87e2e6c6c9314a48a3cd
BLAKE2b-256 b8dc7aa2b4a5d45592359334d201693438528028a3421d422abab970865eca5f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 628a9323e4a979b437b09b602299b232a64bcdfc9ef861e9cc169ae9267a1a1a
MD5 5a6c1fd9e22443a32c4224d8d0eaafc3
BLAKE2b-256 62ed424869843198bca8a89b19d02e752bcace65fa45144a17cb86c653ece08e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.11.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d63c565c18704adb2537e0c2ff145131a96937a9111467775458acddff198cc3
MD5 6f211eee0ff9d98e23d3becb9ee4e041
BLAKE2b-256 e345add806dff195a0298db90e00dd079aa5e4c176b2edf41313aa0f6d920ef7

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