Skip to main content

terrana

Spatial queries and geodesic geometry for Python, backed by a Rust engine (DuckDB with its spatial extension, and the geo crate). Point it at a CSV, Parquet or GeoJSON file with lat/lon columns and query it in-process, or serve it as a REST API. No database to set up, no PostGIS.

pip install terrana        # or: uv pip install terrana

One stable-ABI (abi3) wheel runs on CPython 3.9 and later. No Rust toolchain needed.

Command line

The wheel installs a terrana command, the same as the Rust binary:

terrana serve observations.csv --lat latitude --lon longitude
# → REST API running at http://localhost:8080
curl "localhost:8080/query?lat=36.5&lon=-82.5&radius=10km"

Latitude and longitude columns are detected automatically when --lat/--lon are left out. See the API reference for every endpoint: radius, bounding-box and nearest-neighbour queries, point-in-polygon, filters, paging, and geodesic geometry (area, buffer, convex hull, distance and more).

Library mode (in-process, no server)

import json
import terrana

session = terrana.load_csv("observations.csv")   # also load_parquet / load_geojson
print(session.row_count, session.lat_col, session.lon_col)

# Spatial queries take (lat, lon). Each row is a dict; radius and nearest add `_distance_km`.
rows = session.query_radius(36.54, -82.54, 5000)          # lat, lon, radius in metres
box  = session.query_bbox(35.0, -84.0, 37.0, -81.0)       # min_lat, min_lon, max_lat, max_lon
near = session.query_nearest(36.5, -82.5, 5)              # lat, lon, k

# Geodesic geometry takes (lon, lat), GeoJSON order. GeoJSON results are JSON strings.
d    = terrana.geodesic_distance(-82.54, 36.54, -82.55, 36.55)   # lon1, lat1, lon2, lat2
a    = terrana.geodesic_area('{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}')
hull = json.loads(terrana.convex_hull('{"type":"MultiPoint","coordinates":[[0,0],[1,0],[0,1]]}'))
buf  = json.loads(terrana.buffer(-82.5, 36.5, 5000, segments=64))  # lon, lat, metres

Coordinate order: spatial queries are (lat, lon), like the REST API; geometry functions are (lon, lat), like GeoJSON.

Area and distance use Karney's geodesic algorithms on the WGS 84 ellipsoid, not planar math.

Embedded server

Run the full REST API on a background thread:

import os
import terrana

session = terrana.load_csv("observations.csv")

with session.serve_background(port=8080):
    ...  # http://localhost:8080 is live; it stops when the block ends

server = session.serve_background(port=8080)
server.shutdown()          # or manage it explicitly

# session.serve(port=8080) blocks in the foreground until Ctrl-C

Serving never holds Python's GIL. A port that's already taken raises OSError.

Access control

On the default 127.0.0.1 only this machine can reach the server. Before binding anything else, set a token; every endpoint except /health then needs Authorization: Bearer <token>:

session.serve_background(
    port=8080,
    bind="0.0.0.0",
    token=os.environ.get("TERRANA_TOKEN") or None,
    cors_origins=["https://maps.example.org"],   # default: any origin; ["none"] turns CORS off
)

Binding a non-loopback address without a token raises a RuntimeWarning. The terrana command reads the token from TERRANA_TOKEN or --token-file.

Licensed under MIT or Apache-2.0, at your option.

Metadata

Release files for terrana 0.3.3

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

Source distribution (sdist)

Source distribution for terrana 0.3.3
File Size Uploaded Provenance Actions
terrana-0.3.3.tar.gz 126.6 kB With provenance Details for terrana-0.3.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for terrana 0.3.3
File Actions
terrana-0.3.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for terrana-0.3.3-cp39-abi3-win_amd64.whl
terrana-0.3.3-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details for terrana-0.3.3-cp39-abi3-manylinux_2_28_x86_64.whl
terrana-0.3.3-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for terrana-0.3.3-cp39-abi3-manylinux_2_28_aarch64.whl
terrana-0.3.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for terrana-0.3.3-cp39-abi3-macosx_11_0_arm64.whl
terrana-0.3.3-cp39-abi3-macosx_10_13_x86_64.whl CPython 3.9 abi3 macOS 10.13+ x86-64 Details for terrana-0.3.3-cp39-abi3-macosx_10_13_x86_64.whl

Total release size: 99.9 MB

Release files / terrana-0.3.3.tar.gz

Download URL terrana-0.3.3.tar.gz
Size 126.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c8b57699be46a73c4529c1bcd13790b7aa4783da385e3371c64a5f921fc9d44c
BLAKE2b-256 checksum
How to use checksums
54c083a6d9c2e20c5515f9603baa92feb75823420157054afea7189e53fae1a8
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 Nov 11, 2026.

Transparency log

Release files / terrana-0.3.3-cp39-abi3-win_amd64.whl

Download URL terrana-0.3.3-cp39-abi3-win_amd64.whl
Size 14.9 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e803397d3eaf23fa96cbc6d44667d2acaa6238c2beae09c18d2aae2218d7a6f7
BLAKE2b-256 checksum
How to use checksums
62d776d49ea38da34e712555330fe28d4b23927ac01f2458bab050a4a548419f
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 Nov 11, 2026.

Transparency log

Release files / terrana-0.3.3-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL terrana-0.3.3-cp39-abi3-manylinux_2_28_x86_64.whl
Size 23.3 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
2f6d2024f26f119df35dbe5a041a8a435713be49a6da4bde47246e8e979800a7
BLAKE2b-256 checksum
How to use checksums
f03e512f9c053e926c24ea7e62e62d9ecee86bf41d2d5395bec95dcd49f3cad3
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 Nov 11, 2026.

Transparency log

Release files / terrana-0.3.3-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL terrana-0.3.3-cp39-abi3-manylinux_2_28_aarch64.whl
Size 21.7 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
e64a205706372a576c3db21711fbddb848425844602e42817a167296b6e5ee2d
BLAKE2b-256 checksum
How to use checksums
0ce16e18465d9e3df3a18246fa08a24dc19849e5f3f0c4b13610bc881f36220e
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 Nov 11, 2026.

Transparency log

Release files / terrana-0.3.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL terrana-0.3.3-cp39-abi3-macosx_11_0_arm64.whl
Size 19.5 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
215add6f9a87344a6fcb33b37e4e0c1fc22b3c41b4c801690ecd9f8d8fb827cb
BLAKE2b-256 checksum
How to use checksums
3cdf0a97cd90ea8cf97c11a959ba6da8dcfebda41d7d23c90b1981026ac2d140
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 Nov 11, 2026.

Transparency log

Release files / terrana-0.3.3-cp39-abi3-macosx_10_13_x86_64.whl

Download URL terrana-0.3.3-cp39-abi3-macosx_10_13_x86_64.whl
Size 20.3 MB
Tags CPython 3.9 abi3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
84c05929d7343d0101193d114faf9a1e65ef6f6115667e2eb4d86ec5ed85d1a2
BLAKE2b-256 checksum
How to use checksums
370358ec6a0daa2ca7ce4a55d300ef6a3285f60750bcea60fafba1c1fb871132
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 Nov 11, 2026.

Transparency log

Security for terrana 0.3.3

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 terrana-0.3.3.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 Nov 11, 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