Skip to main content

Run the GeoLibre / whitebox_next_gen geospatial tool suite (WASM/WASI) from Python.

Project description

geolibre-wasm (Python)

Run the geolibre-rust geospatial tool suite (the whitebox_next_gen tools plus GeoLibre's own) from Python. The tools are a single WebAssembly (WASI) module executed in-process via wasmtime, so there is no native install, no GDAL, and no server — just pip install.

This mirrors the JavaScript geolibre-wasm/tools API (list_tools, list_manifests, run_tool), so the two stay in sync.

The import package is geolibre_wasm (the distribution is geolibre-wasm), matching the npm package name and avoiding a clash with the separate geolibre application package.

Install

pip install geolibre-wasm

On first use the runtime (geolibre-cli.wasm, ~20 MB) is downloaded from the matching GitHub release and cached under ~/.cache/geolibre/. To use a local copy instead, set GEOLIBRE_WASM=/path/to/geolibre-cli.wasm or pass wasm_path= to any call.

Usage

Inputs are placed under /work; the tool reads/writes there and any new files come back as bytes. Each input value may be bytes, an http(s) URL to download, or a local file path -- the same for raster and vector inputs:

res = gl.run_tool(
    "write_geoparquet",
    args=["--input=/work/in.geojson", "--output=/work/out.parquet"],
    input={"in.geojson": "https://example.com/data/cities.geojson"},  # fetched for you
)

This downloads the whole file (no HTTP range reads). Works for cog.tif, data.parquet, data.fgb, data.geojson, etc.

Paths are sandboxed. Every path inside args refers to the tool's /work filesystem, not your host disk. input files are placed at /work/<name>, and res.files keys are paths relative to /work. Do your own open() / write() against host paths (e.g. /content/... on Colab) on the Python side, never inside args.

import geolibre_wasm as gl

# Discover tools (each manifest carries a "source": "geolibre" | "whitebox")
tools = gl.list_tools()
manifests = gl.list_manifests()

# Raster: compute slope from a DEM
dem = open("dem.tif", "rb").read()                     # read from host disk
res = gl.run_tool(
    "slope",
    args=["--input=/work/dem.tif", "--output=/work/slope.tif", "--units=degrees"],
    input={"dem.tif": dem},                            # -> /work/dem.tif
)
assert res.exit_code == 0, res.stdout                  # surfaces tool errors
open("slope.tif", "wb").write(res.files["slope.tif"])  # key is relative to /work

# Reproject (warp) to a target EPSG
res = gl.run_tool(
    "reproject_raster",
    args=["--input=/work/dem.tif", "--output=/work/wgs84.tif", "--epsg=4326"],
    input={"dem.tif": dem},
)

# Vector: GeoJSON -> GeoParquet (Hilbert-sorted, bbox covering, ZSTD by default)
gj = open("cities.geojson", "rb").read()
res = gl.run_tool(
    "write_geoparquet",
    args=["--input=/work/in.geojson", "--output=/work/out.parquet"],
    input={"in.geojson": gj},
)
open("cities.parquet", "wb").write(res.files["out.parquet"])

Tools that write a directory tree (e.g. raster_to_tiles) return nested keys:

res = gl.run_tool(
    "raster_to_tiles",
    args=["--input=/work/dem.tif", "--output_dir=/work/tiles", "--min_zoom=16", "--max_zoom=18"],
    input={"dem.tif": dem},
)
for path, data in res.files.items():
    # e.g. "tiles/16/9559/32767.png"
    ...

API

  • list_tools(wasm_path=None) -> list[str]
  • list_manifests(wasm_path=None) -> list[dict]
  • run_tool(tool, args=None, input=None, wasm_path=None) -> ToolResult
  • ToolResult(exit_code: int, stdout: list[str], files: dict[str, bytes])
  • runtime_path(wasm_path=None) -> str — resolve the runtime (explicit > GEOLIBRE_WASM > cached download)
  • download_runtime(dest=None) -> str — fetch the runtime ahead of time

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geolibre_wasm-0.4.4.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geolibre_wasm-0.4.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file geolibre_wasm-0.4.4.tar.gz.

File metadata

  • Download URL: geolibre_wasm-0.4.4.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for geolibre_wasm-0.4.4.tar.gz
Algorithm Hash digest
SHA256 62c89e0f735deb50db7595881a5e4db693d556ca2aa49cda096e45d03b956078
MD5 5ee115acf9899cf095c8b28bbd41f9d1
BLAKE2b-256 fc8509eecefa3126e4c86a975e9364950b600fe627c8beb34eaa77243c8346be

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolibre_wasm-0.4.4.tar.gz:

Publisher: release.yml on opengeos/geolibre-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geolibre_wasm-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: geolibre_wasm-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for geolibre_wasm-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6c35b1ed4de7e77e1145eb1b4d467cad9fed66b706f07ecdebc7644e807434d4
MD5 859d7289722d3ae0f507dac5da972b26
BLAKE2b-256 02580433abfd8e54bb2dfa54df49ca3d017900a532e787b4e4a4a9ec36497979

See more details on using hashes here.

Provenance

The following attestation bundles were made for geolibre_wasm-0.4.4-py3-none-any.whl:

Publisher: release.yml on opengeos/geolibre-rust

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page