Skip to main content

semita

Shortest and cheapest paths and distances on a grid, in C, for Python: jump point search for one path, A* for one where tiles cost differently, and Dijkstra for the cheapest paths from a point to every tile. Semita is Latin for a footpath.

Written for NachOS, a StarCraft II bot library, though nothing in it is about StarCraft.

import numpy

import semita

passable = numpy.ones((5, 5), dtype=bool)
passable[2, :4] = False  # a wall, open at its far end

path = semita.cheapest_path(passable, (0, 0), (4, 0))
assert round(path.distance, 2) == 10.83  # round the wall's end
assert path.tiles[:3].tolist() == [[0, 0], [1, 1], [1, 2]]

assert semita.cheapest_path(passable, (0, 0), (2, 1)) is None  # the end is blocked

paths = semita.cheapest_paths_from(passable, (0, 0))  # to every tile, in one pass
assert paths.distances[4, 0] == path.distance
assert paths.distances[2, 1] == float("inf")
assert paths.path_to((4, 0)).cost == path.cost

# Costs: each value is the cost of moving a unit of distance across its tile, 1 on normal ground and more where it
# is best avoided; 0 blocks, as False does.
costs = numpy.ones((7, 7))
costs[2:5, 2:5] = 10.0  # a patch to keep out of
around = semita.cheapest_path(costs, (3, 0), (3, 6))
assert round(around.cost, 2) == round(around.distance, 2) == 7.66  # round the patch, on ground costing 1
assert semita.cheapest_path(numpy.ones((7, 7), dtype=bool), (3, 0), (3, 6)).distance == 6.0  # straight, on bools

The rules

  • A grid is a 2-D numpy array of bools or real numbers, or anything numpy reads as one, indexed [i, j]. Its values are the tiles' costs: the cost of moving one unit of distance across each, 1 for normal ground, less where movement is faster, more where it is slower or best avoided.
  • 0 and inf block a tile. A grid of bools is the simplest: True costs 1 and False blocks. Otherwise a cost is positive; NaN and negatives raise ValueError.
  • A step goes to one of the eight neighboring tiles, 1 long straight and √2 diagonally, and only between passable tiles. A diagonal step needs both tiles beside it passable too, so no path cuts a corner. A step costs its length times the mean of the costs of the two tiles it joins, so a path costs the same both ways.
  • The start is a path to itself, costing nothing, even on a blocked tile, but no step leaves or enters a blocked one.
  • A start or an end outside the grid raises IndexError; a negative index counts as outside.
  • cheapest_path returns a Path, its distance, its cost and its tiles from the start to the end, or None if there is no path. Of several equally cheap paths it returns one, but which is not part of the contract.
  • cheapest_paths_from returns the cheapest path from the start to every tile, found in one pass, as CheapestPaths: their costs and their distances, two read-only arrays of the grid's shape, inf where no path reaches, and path_to(tile), a tile's path as a Path, or None where none reaches. Where several paths to a tile cost the same, it holds one of them. On a grid of bools the distances are the costs.
  • A grid whose passable tiles all cost the same, a grid of bools included, is searched by jump point search; any other by A*, which visits more tiles, the more so the cheaper the cheapest tile is, since its estimate of what is left is the straight distance times that cost.
  • A grid of bools, or a C-contiguous one of float64, is read as it is; any other is converted on each call, so one searched often is best kept as one of those.

Each search allocates its own memory and releases the GIL, so searches run in parallel on threads. A grid must not be written to while a search reads it.

Building

semita is a C extension on Python's stable ABI, so one wheel serves every Python from 3.12 on a platform. Installing from source compiles it with the platform's own compiler: MSVC on Windows, gcc or clang elsewhere.

uv sync --extra dev
uv run pytest

The tests check every search against scipy's Dijkstra over the same steps.

Releasing

Publish a GitHub release tagged v and the new version, such as v0.2.0. The version is the tag, which setuptools-scm reads from git; no file holds it.

The release workflow then builds the sdist, builds from it a wheel for Linux x86_64 and aarch64, Windows AMD64 and macOS arm64 and x86_64, tests and audits each for the stable ABI alone, checks that the tag is a version, and uploads them to PyPI. Every pull request builds and checks the same files without uploading them.

PyPI trusts the workflow through trusted publishing, from the repository's pypi environment, so no token is stored anywhere.

Metadata

Release files for semita 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semita 0.2.1
File Size Uploaded Provenance Actions
semita-0.2.1.tar.gz 43.0 kB With provenance Details for semita-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for semita 0.2.1
File Actions
semita-0.2.1-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for semita-0.2.1-cp312-abi3-win_amd64.whl
semita-0.2.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details for semita-0.2.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
semita-0.2.1-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.12 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details for semita-0.2.1-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
semita-0.2.1-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for semita-0.2.1-cp312-abi3-macosx_11_0_arm64.whl
semita-0.2.1-cp312-abi3-macosx_10_13_x86_64.whl CPython 3.12 abi3 macOS 10.13+ x86-64 Details for semita-0.2.1-cp312-abi3-macosx_10_13_x86_64.whl

Total release size: 219.1 kB

Release files / semita-0.2.1.tar.gz

Download URL semita-0.2.1.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
62874753a9f9bcc7034fb5cd99812c9b9b0dae4b4eac25e4df702912a9dc7a62
BLAKE2b-256 checksum
How to use checksums
df684fbee71f02dc2647c85800ee13d1c3b1427c919b3cdc8022b1d885388522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / semita-0.2.1-cp312-abi3-win_amd64.whl

Download URL semita-0.2.1-cp312-abi3-win_amd64.whl
Size 19.9 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4c0df3cddd298edbe61290f3b77cd95d3ba44198a43db185964419844b13714e
BLAKE2b-256 checksum
How to use checksums
d3cffc54dce8a3fe40e9abbe32281f9e3fdb3f58502808f0d16f412a0c993f58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / semita-0.2.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL semita-0.2.1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 59.3 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
063cb15bd50863e58f6ef868ed758449b90645edb2ce6d98caba01efeed31462
BLAKE2b-256 checksum
How to use checksums
3d5f0667eed41374b2a83ec9531d41d42728cd5a4f1807b458e9420a6c1ac8f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / semita-0.2.1-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL semita-0.2.1-cp312-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 57.7 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
8263e4c0d270a4510e94029e8a1555fd8daa40927bf7512d20cd457007e9fe08
BLAKE2b-256 checksum
How to use checksums
d8849cf320291352999c9a7676998729139ba40bcf9bc0af38bd8d68c1f07ed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / semita-0.2.1-cp312-abi3-macosx_11_0_arm64.whl

Download URL semita-0.2.1-cp312-abi3-macosx_11_0_arm64.whl
Size 19.5 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
91c5e30e4ccd762de2a276f4c31b7017511b301074c7a18025eb9353ba662a25
BLAKE2b-256 checksum
How to use checksums
f87faded15ba8654f9092522f0c52a7be7f6ffe0783fb0f1beb94804dfd09dd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / semita-0.2.1-cp312-abi3-macosx_10_13_x86_64.whl

Download URL semita-0.2.1-cp312-abi3-macosx_10_13_x86_64.whl
Size 19.8 kB
Tags CPython 3.12 abi3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
bd90ac3a27c7acdb6d68169bf46ae9cdf7693d20e71a051aaf7cf2ae1c33c5a7
BLAKE2b-256 checksum
How to use checksums
dad8119cbc50f26a479d48961c97a6f6f3ce69c96ea6cd542474ec714e46d2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for semita 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for semita-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page