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

Uploaded CPython 3.13Windows x86-64

cython_extensions_sc2-0.10.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.10.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.10.0-cp312-cp312-win_amd64.whl (431.7 kB view details)

Uploaded CPython 3.12Windows x86-64

cython_extensions_sc2-0.10.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.10.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.10.0-cp312-cp312-macosx_11_0_arm64.whl (554.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cython_extensions_sc2-0.10.0-cp312-cp312-macosx_10_13_x86_64.whl (595.5 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

cython_extensions_sc2-0.10.0-cp311-cp311-win_amd64.whl (440.7 kB view details)

Uploaded CPython 3.11Windows x86-64

cython_extensions_sc2-0.10.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.10.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.10.0-cp311-cp311-macosx_11_0_arm64.whl (558.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cython_extensions_sc2-0.10.0-cp311-cp311-macosx_10_9_x86_64.whl (612.6 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1c163a2434d210779d5312f34b19b3a1038c38d405b47f96e4b680a6cd33a896
MD5 807ebb39b392253b53a61b61d11804f5
BLAKE2b-256 b86a136d3a942772a3ae2392b07c42ea04bc87466b683e49cf1c365f36a28698

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8c949d09f6d40cc0af3f66c0b453cdc2446394b66eb2f2c7797f71a169482685
MD5 b96595332f035951dbb5b157f63e0fa5
BLAKE2b-256 2368c3614884f6d51cdb97ba99a646989ff2dc1b048f0e8bfa67527fb27a3ebf

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.10.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.10.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 498304cd48350813c75b92a8ccdb4632c9cb999706a10623fe5bad43e9c48a3b
MD5 1a6726606a432255da8a65bfd3d1efe8
BLAKE2b-256 d8905abfb8125c113c3e97213ec58b2296c83522b11ea8a2bc74cc06f8bd31df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5d2f3829bb05e3fa24e508f6508e5a63f776e50e99c42a31723f19d095ec9010
MD5 ba4ea53cf91b7a6e09d73fc00a23487b
BLAKE2b-256 72381bcf159bd22953591e16d8e0a10c9d4671bb16cd4ab8cc46aa83275933df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5fabc937c17e05ece8ca50220f70006b12c1220d83146760d7f58caac9f7dcc3
MD5 d146d5e1049d82365d70e35e02ec617b
BLAKE2b-256 9000a05aaaa9aaf6445df95b0e9f0091da514fafbc5e077b8e3e9d319c16c085

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.10.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.10.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 587ba681426d94c0ee466d71d26175a85eefd468b0188a08449b8fef2308f54c
MD5 14ba57b6805adc8966e5e65341e1c1ac
BLAKE2b-256 9c0e89f5950d031b9330922af8ff646a0295af039bd7138ead51c549ccef9ebe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bb08ecb97763c78559cacadc20bd4ba0b1da8ac9689fbb0bf968358abd0881c6
MD5 d15391fee2c012afb42e0c9bc97ec432
BLAKE2b-256 0f3fb8d1788c9ce3b70b23376bb65168e55d5f74be7c3bc6bf77ffaa10097c10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a0b10b07902b7566ae29df47e3d30708c8c80676f095f69a85bac2ec7491f2c4
MD5 308282b2f00a630aa5f6e19b29feda40
BLAKE2b-256 340a95179c4bc2c710d6bba35b76320655dc3d176ac99135caa399d0c714460b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9c2d5eea363f573e1c414ef245cca58d1ce3956dc4ec3e85cc5b37e2a97fa667
MD5 701bcb682600f75cbcaeaca80693bc07
BLAKE2b-256 36d5feb1324c6c3e53de62bb8b00b03028f2cc62623cc0ab986e295b491484cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 93fe20c54372a21073cea584168adfd5ac3ddcc667cd392274ef9e8d45d184bb
MD5 e3dd9a42428ec5d971ffbb43cf403115
BLAKE2b-256 7d73be9f54ff5e857febf043aad93e521d50b05fd556ab44ccea74e33933dd83

See more details on using hashes here.

File details

Details for the file cython_extensions_sc2-0.10.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.10.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d8fd32815075b93fb580caeafaaaeb18edfd9561e31a9610a30c7481fc3b447a
MD5 74331b0cdb25f77ea1110ca7b61e2577
BLAKE2b-256 f80f6130d2e982d64f6d5f29af0c941e4ed56b95ada7d3cb11d7368412c281bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b29e8c39aa3b3d108e52a10356647302ee09b7446511884db907ef84078647af
MD5 fd4e0c426e03fd93b64a8c1bc7ab2ddb
BLAKE2b-256 22292838442938bd755c8b112f3d6a12e3dc5f15cf0d0c1b6965650c21c2eabc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cython_extensions_sc2-0.10.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 800b3576c8efd713ca0659c2864225f206c7a3079cc00b68de0e8c8cbe3c2fe7
MD5 bf1f2e9f7f5aca44090d33f3178afe25
BLAKE2b-256 f6064ce8b123d5205d02bf4367eabbefba59cfd8826d330d5f53d4825c89e3ca

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