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.find_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.find_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.find_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.find_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.
  • find_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.1.0

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.1.0
File Size Uploaded Provenance
semita-0.1.0.tar.gz 43.0 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for semita 0.1.0
File
semita-0.1.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
semita-0.1.0-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
semita-0.1.0-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
semita-0.1.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
semita-0.1.0-cp312-abi3-macosx_10_13_x86_64.whl CPython 3.12 abi3 macOS 10.13+ x86-64 Details

Total release size: 219.1 kB

Release files / semita-0.1.0.tar.gz

Download URL semita-0.1.0.tar.gz
Size 43.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7deae249cb7870d5f0aa089c03d2194dc7752e8ce327f543eaf01c360b5c1718
BLAKE2b-256 checksum
How to use checksums
6b433ebca39edafe0be72851eff8f039801fc065c664cf5ee8b87315ce0d36fe
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 21, 2026.

Transparency log

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

Download URL semita-0.1.0-cp312-abi3-win_amd64.whl
Size 19.9 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f72af0d3998927d1775105613e9e8328ab4ac51524b3453d7671564a11491a5f
BLAKE2b-256 checksum
How to use checksums
c9c15634924fcd0d57f2f5ae20c2e7079e5cf5159e5d4377f981429c43cbbc50
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 21, 2026.

Transparency log

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

Download URL semita-0.1.0-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
b013968f35ac999a1c62d5127e7349646165ed99234e42dde4f1fabee2e673be
BLAKE2b-256 checksum
How to use checksums
1a5c0077da9fc089e35478b261958fce19b21949880f6d676c16760c692a0f5b
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 21, 2026.

Transparency log

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

Download URL semita-0.1.0-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
8686a862e075ea8e45f8ca6105c0ea07e7452512fe880be76e2b99c83ef756b5
BLAKE2b-256 checksum
How to use checksums
8899d8ce07c75641079455661ba42525ea45023286db938a8adec9323c1e7727
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 21, 2026.

Transparency log

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

Download URL semita-0.1.0-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
0a9e016ffb9c309881577b25f3916b5f877df91f85d3e02799ad7b189a290c69
BLAKE2b-256 checksum
How to use checksums
11e019264742765f9b465f9f2ae49a969903177edd54a5feedd2599127960ebd
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 21, 2026.

Transparency log

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

Download URL semita-0.1.0-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
9b24b5b1fe1e87d65e4a1ad05771bd9a5201ae9d90dde845cd00eaca3ffb3d7f
BLAKE2b-256 checksum
How to use checksums
1fd6f5f9333c0af4a5e127ba72d4e2cbb47302630dfb2430f9dd7f5814a5f352
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 21, 2026.

Transparency log

Security for semita 0.1.0

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.1.0.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 21, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files Full provenance

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