Skip to main content

basemaplibre

Basemaps for matplotlib and GeoPandas from MapLibre styles, with the parameters of contextily's add_basemap.

contextily downloads raster tiles in Web Mercator, merges them and warps them to the CRS of your data. basemaplibre renders the style (vector tiles, labels, icons) with ml2drender for the extent of the axes, at their resolution and directly in their CRS, so labels stay upright and sharp. No GPU, no browser, no system libraries.

GitHub Checks GitHub Workflow Status - PROD pre-commit.ci status Codecov Package version Supported Python versions

Documentation · Style gallery · API reference

The same axes in EPSG:3035 with the default basemaps of contextily, whose labels are turned and blurred, and of basemaplibre

Installation

pip install basemaplibre

Usage

import geopandas
import basemaplibre as bml

gdf = geopandas.read_file("districts.gpkg")
ax = gdf.plot(alpha=0.5, edgecolor="k")
bml.add_basemap(ax, crs=gdf.crs, source="OpenFreeMap.Positron")

labels="above" draws the map under your data and its labels above it:

A choropleth over a basemap with its labels hidden by the data, and with labels above it

add_basemap(ax, ...) Draws a style under the data of ax.
add_attribution(ax, text, ...) Writes text in the bottom right corner of ax, wrapped to its width, on a translucent white box as MapLibre does.
set_cache_dir(path) Keeps downloads in path, reused by later sessions that set it again, instead of a temporary directory removed at exit.
STYLES Named styles that load without an API key, for source.

Differences from contextily

  • source is a MapLibre style: a dict, the URL of its JSON, a name of STYLES (default OpenFreeMap.Liberty) or a local .json file. Other sources (an xyzservices provider, a URL of raster tiles, a raster file) are left to contextily.add_basemap, with a UserWarning. contextily is not a dependency: install it for those.
  • The style is drawn directly in crs (anything pyproj.CRS.from_user_input reads) if ml2drender supports the projection, so resampling is ignored. Axes that stretch latitudes, as GeoPandas does in EPSG:4326, get the projection they show, so labels keep their shape.
  • zoom is contextily's zoom of 256-pixel tiles (the style is evaluated at MapLibre zoom zoom - 1); "auto" draws the style at its size on a web page.
  • The basemap is rendered when it is added, and again when the axes are drawn with other limits, at another size or at another dpi: it stays sharp and up to date after zooming, panning, fig.tight_layout() or fig.savefig(dpi=300). Rendering may download tiles, and its errors are raised where the figure is drawn. The image has the dpi the figure is drawn at, but 200 pixels to the inch at least.
  • New: labels=False drops the labels and icons, labels="only" draws only them, above the data, and labels="above" draws the map under the data and its labels above it; pixel_ratio fixes the resolution; load replaces fetching with HTTPX. OpenHistoricalMap's styles are drawn as of today, as on its website.
  • Downloads are cached on disk as in contextily (set_cache_dir keeps them across sessions), but for the style and its TileJSON, which name the current tiles. Failed requests are tried twice more.

Styles

STYLES has maps of the world (OpenFreeMap, VersaTiles, CARTO, Maptoolkit, OpenHistoricalMap, MapLibre) and of national mapping agencies (basemap.de, swisstopo, IGN, PDOK, GSI), terrain (Mapterhorn) and imagery (VersaTiles, EOX, USGS, GSI, PDOK, IGN). The gallery shows each of them, with the coverage and terms of their services: check the terms before heavy use.

Maps of nine of the named styles

Mapterhorn.Hillshade is transparent, to shade another basemap (here, under its labels):

bml.add_basemap(ax, source="OpenFreeMap.Positron", labels="above")
bml.add_basemap(ax, source="Mapterhorn.Hillshade")

Development

uv sync                # install
uv run pre-commit install --hook-type pre-commit --hook-type commit-msg
uv run tox             # tests
uv run tox -e docs     # execute the notebooks, draw the gallery, build the docs to site/
uv run zensical serve  # preview them
uv run python scripts/readme.py  # draw the images of the README

The notebooks in examples/ are kept without outputs: they are executed when the docs are built, on release.

Metadata

Release files for basemaplibre 0.1.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 basemaplibre 0.1.0
File Size Uploaded Provenance Actions
basemaplibre-0.1.0.tar.gz 21.9 kB Without provenance Details for basemaplibre-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for basemaplibre 0.1.0
File Interpreter ABI Platform Actions
basemaplibre-0.1.0-py3-none-any.whl Python 3 none any Details for basemaplibre-0.1.0-py3-none-any.whl

Total release size: 45.7 kB

Release files / basemaplibre-0.1.0.tar.gz

Download URL basemaplibre-0.1.0.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6303f401ff73dc9efb7593affaf60f6173cb7de56145751a1b646617b05d48e2
BLAKE2b-256 checksum
How to use checksums
2c8ef33f2371b38b57fa270b8dcc06f7d2830a6441e934a5c7fa829b98b3e2e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / basemaplibre-0.1.0-py3-none-any.whl

Download URL basemaplibre-0.1.0-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79f78b3cad6c6efcec895732eaabd1877cacca7f10e45bcdfa538eb9deefbf56
BLAKE2b-256 checksum
How to use checksums
34878ef2bd69fb23c2519b1aeede40afe0d9f7fd616f7e314d06fd75d16a72a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for basemaplibre 0.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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