Skip to main content

AI / Agents

llms.txt
llms-full.txt

Meta

Requires: Python >=3.9
Provides-Extra: plotnine, dev
Package Info

basemapper

basemapper renders MapLibre GL basemaps (vector and raster styles) headlessly with a Rust core: to PNG, NumPy arrays or true vector SVG, at any fractional zoom and pixel ratio, and as matplotlib and plotnine layers that render at the output resolution.

Also available for R — the same Rust core, and the same functions and argument names (R’s verb(m, ...) is m.verb(...) here). R documentation

Installation

Prerequisites

The package compiles a Rust extension during installation. Install Rust for your platform before proceeding.

Windows

winget install Rustlang.Rustup

After installation, open a new terminal so rustup and cargo are on your PATH.

macOS

brew install rustup
rustup-init

Or without Homebrew:

curl https://sh.rustup.rs -sSf | sh

Linux

curl https://sh.rustup.rs -sSf | sh

Install the package

Install the development version from GitHub.

With pip:

pip install "basemapper @ git+https://github.com/ar-puuk/basemapper@v0.1.1#subdirectory=py-basemapper"

These install the latest release, v0.1.1 (all releases). For the development version, leave out @v0.1.1.

With uv, into a project or the current environment:

uv add "basemapper @ git+https://github.com/ar-puuk/basemapper@v0.1.1#subdirectory=py-basemapper"
uv pip install "basemapper @ git+https://github.com/ar-puuk/basemapper@v0.1.1#subdirectory=py-basemapper"

With conda (or mamba), conda-forge provides the dependencies and the Rust toolchain, and pip builds basemapper from GitHub inside the environment:

conda create -n basemapper -c conda-forge python numpy pyproj matplotlib xarray rust pip
conda activate basemapper
pip install "basemapper @ git+https://github.com/ar-puuk/basemapper@v0.1.1#subdirectory=py-basemapper"

or as an environment.yml (conda env create -f environment.yml):

name: basemapper
channels: [conda-forge]
dependencies:
  - python>=3.9
  - numpy
  - pyproj
  - matplotlib
  - xarray
  - rust
  - pip
  - pip:
      - "basemapper @ git+https://github.com/ar-puuk/basemapper@v0.1.1#subdirectory=py-basemapper"

For geom_basemap() in plotnine, install basemapper[plotnine] in place of basemapper.

A PyPI release is planned once the package stabilises.

Quick example

import basemapper
from basemapper import basemap_provider, tile_style, wms_style

# Built-in basemaps by leaflet name (list_providers(), basemapper.providers);
# the name works as a style
style = "OpenFreeMap.Liberty"
style = basemap_provider("Esri.WorldGrayCanvas", type="raster")   # pick the form
style = basemap_provider("OpenFreeMap.Liberty", tiles="data/omt.pmtiles")   # your own tiles

# Stack parts of basemaps: imagery under a vector basemap's labels
hybrid = ["Esri.WorldImagery", basemap_provider("OpenFreeMap.Liberty", labels="only")]
# labels=False / "only", features=["water", "roads"] / ["-buildings"]

# A view: centre + zoom, or bounds to fit
m = basemapper.basemap(style, 800, 600, center=(-122.45, 37.75), zoom=12, pixel_ratio=2)
m.render_png(path="sf.png")        # 1600 x 1200
m.render_svg(path="sf.svg")        # true vector
m.set_view(zoom=13).get_bounds(lonlat=True)

# One-shot render of bounds to a (height, width, 4) uint8 array
a = basemapper.render_basemap_raw([-122.5, 37.7, -122.4, 37.8], 400, 300, style)

# Your own tile data works as a style: tile URLs, TileJSON, PMTiles
# archives (URL or local file), ArcGIS services
m = basemapper.basemap("data/area.pmtiles", 800, 600, bounds=[-122.5, 37.7, -122.4, 37.8])
style = tile_style("https://example.com/{z}/{x}/{y}.png", maxzoom=16)   # with overrides
style = wms_style("https://gis.example.com/wms", layers="imagery")

Get started

See the documentation for a walkthrough of rendering basemaps with matplotlib, plotnine, and raw RGBA output.