Skip to main content

wkp (Python binding)

Python package with a minimal Shapely-first API on top of the WKP Rust core.

Architecture

  • src/lib.rs: the wkp._core extension, written with pyo3 and rust-numpy over wkp (core/)
  • python/wkp/: the pure-Python package (Shapely conversion, GeometryFrame, contexts)
  • Built with maturin as abi3 wheels: one wheel per platform works on every CPython from 3.10 up (including 3.14)
  • The package version comes from the Cargo workspace (Cargo.toml at the repo root); a runtime check enforces core compatibility
  • Large inputs are processed with the GIL released

Dependencies

  • Python >= 3.10
  • build: Rust (stable) and maturin (pulled in automatically by pip install)
  • runtime: numpy, shapely
  • dev/test: pytest, polyline

Install (dev)

From repo root:

pip install -e "bindings/python[dev]"     # or: cd bindings/python && maturin develop --release

Re-run after changing Rust code (Python changes are picked up directly).

Build

cd bindings/python
maturin build --release      # wheel for this platform, in ../../target/wheels
maturin sdist                # source distribution

Test

pytest bindings/python/tests

API

Geometry encode / decode

encode(geom, precision, *, ctx=None) -> bytes
decode(encoded, *, ctx=None) -> DecodedGeometry
decode_header(encoded) -> (version, precision, dimensions, geometry_type)

encoded can be bytes, str (e.g. read from a text column or JSON) or any other bytes-like object. Encoders return bytes; use .decode("ascii") for a str.

GeometryFrame — low-level flat representation

decode_frame(encoded, *, ctx=None) -> GeometryFrame
encode_frame(frame, *, ctx=None) -> bytes

GeometryFrame fields: version, precision, dimensions, geometry_type, coords (numpy float64 array, shape (n_points, dimensions)), segment_point_counts, group_segment_counts.

Methods: to_geometry() -> Shapely geometry, to_buffer() -> bytes, GeometryFrame.from_buffer(buf) -> GeometryFrame.

Float helpers

encode_floats(floats, precisions, *, ctx=None) -> bytes
decode_floats_array(encoded, precisions, *, ctx=None) -> np.ndarray  # flat (N*dims,) float64
decode_floats(encoded, precisions, *, ctx=None) -> np.ndarray        # shaped (N, dims) float64

decode_floats_array returns a flat 1D float64 array of interleaved values [x0, y0, x1, y1, ...] — a single allocation with no reshape. Use arr.tobytes() to treat it as a raw byte buffer for shipping over sockets or shared memory.

decode_floats wraps decode_floats_array and returns a (N, dims) 2D view (zero-copy reshape). Use .tolist() on the result if you need plain Python lists.

Context

Context()

A Context owns a reusable native C buffer pool. Buffers grow to fit the largest geometry processed, then stay allocated and get reused on subsequent calls — avoiding repeated allocations.

Thread-local (default) — one context per thread, created lazily, lives for the thread's lifetime:

encoded = encode(geom, precision)   # ctx=None uses the thread-local pool
decoded = decode(encoded)

Explicit reuse — create one context and pass it to a batch of calls; the pool is freed when the object is garbage-collected or explicitly deleted:

ctx = wkp.Context()
for geom in large_collection:
    encoded = encode(geom, precision, ctx=ctx)
    ...
del ctx  # releases native buffers immediately

A Context belongs to one thread at a time: using the same one from two threads concurrently raises RuntimeError: Already borrowed (use the default thread-local contexts, or one Context per thread). Inputs of 16k+ values are processed with the GIL released, so threads encoding or decoding large geometries run in parallel.

Per-call (no persistent memory) — create a fresh context for each call; buffers are freed as soon as the call returns:

encoded = encode(geom, precision, ctx=wkp.Context())

This costs one allocation/free per call but guarantees no native memory persists between calls — useful when peak RSS matters more than throughput.

Example

from shapely.geometry import LineString
from wkp import decode, decode_frame, encode

geom = LineString([
    (174.776, -41.289),
    (174.777, -41.290),
    (174.778, -41.291),
])

encoded = encode(geom, precision=6)
decoded = decode(encoded)

print(encoded)
print(decoded.geometry.wkt)

# Access the flat frame directly (useful for numpy / bulk processing)
frame = decode_frame(encoded)
print(frame.coords)          # numpy float64 array, shape (3, 2)
buf = frame.to_buffer()      # compact binary blob
frame2 = frame.from_buffer(buf)  # round-trip

Benchmark

Full geometry encode/decode comparison against Shapely WKB/WKT:

python bindings/python/benchmark/benchmark.py --linestring-points=10000 --precisions=5 --max-iterations=1000 --max-duration=1

Flat-array API micro-benchmark (encode/decode/decode_frame/decode_floats_array):

python bindings/python/benchmark/bench_flat_api.py
python bindings/python/benchmark/bench_flat_api.py --points=50000 --iterations=200

Example results (wkp 0.6.0, Python 3.10, WSL2 on an i7-12700H, one core; x86-64, so the SIMD paths are used):

Method Source kb Encode (ms) Decode (ms) Total (ms) Iters
shapely_wkb nz-coast 156.3 0.23 ± 0.03 0.06 ± 0.02 0.29 ± 0.04 2000
shapely_wkt nz-coast 379.7 1.32 ± 0.15 4.37 ± 0.33 5.70 ± 0.35 988
shapely_wkt_5dp nz-coast 202.8 1.38 ± 0.12 2.76 ± 0.20 4.15 ± 0.24 1088
wkp-5p-bytes nz-coast 42.9 0.06 ± 0.02 0.05 ± 0.01 0.11 ± 0.02 2000
wkp-5p-str nz-coast 42.9 0.06 ± 0.01 0.05 ± 0.01 0.11 ± 0.02 2000
wkp-frame-5p nz-coast 42.9 0.07 ± 0.03 0.03 ± 0.01 0.10 ± 0.04 2000
shapely_wkb random 156.3 0.22 ± 0.03 0.06 ± 0.06 0.29 ± 0.07 2000
shapely_wkt random 378.4 1.35 ± 0.35 4.13 ± 0.27 5.53 ± 0.62 983
shapely_wkt_5dp random 163.9 1.49 ± 0.19 2.57 ± 0.25 4.06 ± 0.31 1058
wkp-5p-bytes random 72.2 0.06 ± 0.02 0.07 ± 0.01 0.13 ± 0.02 2000
wkp-5p-str random 72.2 0.06 ± 0.02 0.07 ± 0.03 0.13 ± 0.04 2000
wkp-frame-5p random 72.2 0.06 ± 0.01 0.05 ± 0.01 0.11 ± 0.02 2000

On the same machine, the 0.5.0 (nanobind + C core) build took 0.17 ms to encode and 0.18 ms to decode nz-coast (wkp-5p-str): 0.6.0 is about 2.8x / 3.6x faster.

Packaging / release

  • abi3 wheels (manylinux and musllinux x86_64/aarch64, Windows x64/arm64, macOS x86_64/arm64) and the sdist are built in .github/workflows/python.yml with PyO3/maturin-action, then tested on Python 3.10 and 3.14.
  • Release/publish runs from tag pushes or workflow_dispatch in .github/workflows/python.yml.
  • Tag publish (recommended): push a tag in the exact format pypi-vX.Y.Z (for example pypi-v0.1.0).
  • Publish order is always TestPyPI first, then PyPI.
  • Python releases are binding-specific. Product-level GitHub releases use the separate wkp-vX.Y.Z tag flow.

Manual publish from GitHub

  1. Open Actions -> Build and upload to PyPI.
  2. Run workflow dispatch.
  3. The workflow publishes to TestPyPI and then PyPI automatically.

If you only publish via git tags, manual dispatch is optional and can be removed.

Metadata

Release files for wkp 0.6.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 wkp 0.6.0
File Size Uploaded Provenance
wkp-0.6.0.tar.gz 114.4 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for wkp 0.6.0
File
wkp-0.6.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
wkp-0.6.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
wkp-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
wkp-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
wkp-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
wkp-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
wkp-0.6.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
wkp-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.4 MB

Release files / wkp-0.6.0.tar.gz

Download URL wkp-0.6.0.tar.gz
Size 114.4 kB
Tags Source
SHA-256 checksum
How to use checksums
946998c07296f6fee31998bb13cd76675ba5c3f452047c07bc9aac97d4eb7f4b
BLAKE2b-256 checksum
How to use checksums
c4d32a3f360f432b3387b1240b579526ebc1c6507aa73293668a4dcacf0538fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-win_arm64.whl

Download URL wkp-0.6.0-cp310-abi3-win_arm64.whl
Size 168.7 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
584c0cc4b5ccb2de5fc8a656afd659840babf0d82073f391f03db9aff99f117d
BLAKE2b-256 checksum
How to use checksums
92e826e8790dd349d34b7bd9e3a8f36d69f248361e88603f021a131521954824
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-win_amd64.whl

Download URL wkp-0.6.0-cp310-abi3-win_amd64.whl
Size 179.9 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
36ba964a6781baa765ddca9e64c1bd1a2fc5217d67fb1768ae15c3f7b5b6d5e6
BLAKE2b-256 checksum
How to use checksums
b6a13b4196b80ee5c78519221523f1f20b33204c9f148dd4c00a91bba50f9426
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL wkp-0.6.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 477.1 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
66eaf31295fe575c3765f416473714935a1256e42512b3be2038eb2bbb9dec0b
BLAKE2b-256 checksum
How to use checksums
c40c91c60f1a29f8bcb75f5b4bf7b82f9481a896ef7a5426b34dd37fabd9d99a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL wkp-0.6.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 428.3 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
b2fd9ce895efcebe643c5f480ba1a563e8b7b310835af8df4679e01d43a67d1b
BLAKE2b-256 checksum
How to use checksums
f4d788433515b06a1028b79b009d38d3ad4d00da08706468fe5f13c178ab63a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wkp-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 265.2 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
575e38ee9f5e0ae624ffb6288a44e36730cca5d5d3ee62c7c8828eaa92180241
BLAKE2b-256 checksum
How to use checksums
364c49b3f9c9f5c634ede30ba07393a190718dafb090af636596c3c212147bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL wkp-0.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 249.9 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e935f4c6b2a481579fbb55ef2bf1819bee08c164a402b1e2cf7e19ce7000e155
BLAKE2b-256 checksum
How to use checksums
2f32bdd31954e3d011b2f3e06a7bb95a05a7ea0ef227f4023ec3c5ddcc8c8167
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL wkp-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
Size 240.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
44192b54df79a4d5ba52b72efe22a4f1b7c56a0b7fa87b660e8fd25fc29f835d
BLAKE2b-256 checksum
How to use checksums
d4aab57152b34b76c71a634d32de7cda3e971a8083c097a5bc7e347e7e55787e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / wkp-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL wkp-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 254.1 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
517858abeb681438130fdf80229109c96c0c05c6ed494b4131cc47b6f9e37b99
BLAKE2b-256 checksum
How to use checksums
93bf65109753c8b477c74da0a8c1d672c45a8b385ba38f6c9ffa0de6d37c99b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 wkp 0.6.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 9 files in this release have been uploaded with provenance metadata.

Select from 9 files

Attestation for wkp-0.6.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.

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