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.

Supported geometries are Point, LineString (and LinearRing, which decodes as a LineString), Polygon, MultiPoint, MultiLineString and MultiPolygon, in 2D or 3D (XYZ). Geometries with M values raise ValueError: Shapely cannot rebuild them when decoding. Data with more than 3 dimensions can be encoded with encode_frame and decoded with decode_frame.

Limits

Precision is an integer from 0 to 63, and every |value| × 10^precision must be below 2^58 (e.g. ±2.8 × 10^12 at precision 5). Geometries and float streams have 1 to 16 dimensions, and values must be finite. Anything else raises ValueError.

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 reusable native buffers. 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  # in CPython, releases the native buffers once nothing else refers to ctx

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 GeometryFrame, 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 = GeometryFrame.from_buffer(buf)  # round-trip
assert frame2 == frame

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.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 wkp 0.6.1
File Size Uploaded Provenance
wkp-0.6.1.tar.gz 116.5 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for wkp 0.6.1
File
wkp-0.6.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
wkp-0.6.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
wkp-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
wkp-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
wkp-0.6.1-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.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
wkp-0.6.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
wkp-0.6.1-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.1.tar.gz

Download URL wkp-0.6.1.tar.gz
Size 116.5 kB
Tags Source
SHA-256 checksum
How to use checksums
df5b518a643286298a2272c211136a309ab670ab261700583571d5026f442a3a
BLAKE2b-256 checksum
How to use checksums
0fe605ccc95f80c276ef111e566149c1e6ba5230a75011dd00510a4169f80a15
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-win_arm64.whl

Download URL wkp-0.6.1-cp310-abi3-win_arm64.whl
Size 170.1 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
a98308cb358688e303ada5cf7628cfcde336dc8eb91048735f0f86642c21c14f
BLAKE2b-256 checksum
How to use checksums
ed3b35cbdc5856bf84c8b109842319c57138258c59e0d175841cee56d3d62053
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-win_amd64.whl

Download URL wkp-0.6.1-cp310-abi3-win_amd64.whl
Size 181.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5fdb0c634236359ed94a78a1e6b9e9ce69044bd3a9d7727059c482d5b3979359
BLAKE2b-256 checksum
How to use checksums
db308831df3b7b9065384a0e52fc12b75393424b9c68465dbd35965e510c069a
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL wkp-0.6.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 478.4 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
c0d070fa551ba61ab6bf07903174b05c69fc3c9fb2c2a6da31cdf071adbad351
BLAKE2b-256 checksum
How to use checksums
bf863a37efd94ccaf1977d64090627674aca0610d05ba034a71276f20e9c2f3f
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL wkp-0.6.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 429.9 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
ea4f7e450a3d9a81cf58b167ef7eaab397b2482230b95764a443c5059f50e12a
BLAKE2b-256 checksum
How to use checksums
365c6b8497a424d55091c1fe6d477f5132763e58c4d2424a8265552649f07ed3
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL wkp-0.6.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 266.6 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
4c570b4d0f9a496fb6c7eac54d901827f6b929a0e9ca46b6f6d4ea0427defe30
BLAKE2b-256 checksum
How to use checksums
460b17b8595248525a65dda7c8eb67c66c0c4ac3ea75c8f69e83d76061349b7d
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL wkp-0.6.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 251.5 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
80ae5d05e19d09cbfcc14fd42257dd550e8f1fb03bbed983f0060a53cde22f80
BLAKE2b-256 checksum
How to use checksums
eb3ebdc05236ac09816ee279d879a5d5b69d9a27046ed7d3fd0bccc18f946183
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL wkp-0.6.1-cp310-abi3-macosx_11_0_arm64.whl
Size 242.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4b2ecb852cf5e36e53a48fb85701d9a4e00104ba7b71e7538703bf95b987c7d8
BLAKE2b-256 checksum
How to use checksums
15055cafab1e0c40d0dcd399128f088c85b3c52d40b97b4d9b54193bbd70ac2f
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 22, 2026.

Transparency log

Release files / wkp-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL wkp-0.6.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 255.2 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
590c764f06cbca10925d393f5154fc546f57a0350fb07338969805c3b5056e86
BLAKE2b-256 checksum
How to use checksums
825c243875eea5124162957f18e4087354ab7154dbc4cf91312aaae4df0a5893
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 22, 2026.

Transparency log

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

Select from 9 files

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