Skip to main content

MapLibreum logo

CI Documentation Build PyPI

MapLibreum

A Python library for creating interactive MapLibre maps, like Folium but for MapLibre.

Installation

pip install maplibreum

Development

pip install -e .
pytest

Usage

from maplibreum import Map

# Create a map centered at a specific location
m = Map(center=[-23.5505, -46.6333], zoom=10)

# The default is OpenFreeMap Liberty: a detailed basemap with no API key.
# Other keyless presets include liberty, bright, positron, fiord, and
# openfreemap-dark.
m_light = Map(map_style="positron")

# Pin a compatible MapLibre GL JS version (defaults to 6.0.0)
m_custom = Map(maplibre_version="6.0.0")

# Add a marker at the map center
m.add_marker(popup="Hello, MapLibre!")

# Or specify coordinates for the marker
m.add_marker(coordinates=[-23.55, -46.63], popup="Another marker")

# Add a heatmap layer from GeoJSON points
geojson = {"type": "FeatureCollection", "features": []}
source = {"type": "geojson", "data": geojson}
m.add_heatmap_layer("heat", source)

# Register event callbacks (Jupyter notebooks)
def handle_click(evt):
    print("Clicked at", evt["lngLat"])
m.on_click(handle_click)

# Enable built-in controls
m.add_control("geolocate", "top-right", options={"trackUserLocation": True})
m.add_control(
    "attribution", "bottom-right", options={"customAttribution": "My Data"}
)

# Controls
from maplibreum.controls import MiniMapControl, MeasureControl, SearchControl

# Add a minimap
m.add_control(MiniMapControl())

# Add a measure control
m.add_measure_control()

# Add a search control
# You will need an API key from a geocoding provider like Maptiler.
# https://www.maptiler.com/cloud/keys/
m.add_search_control(SearchControl(provider="maptiler", api_key="YOUR_API_KEY"))

# Enable terrain and atmospheric effects
m.add_dem_source("terrain", "https://example.com/dem.png")
m.set_terrain("terrain")
m.add_sky_layer()
m.set_fog()

# Save the map to an HTML file
m.save("my_map.html")

# Switch to an Albers projection and enable RTL/mobile options
m.set_projection({"name": "albers", "parallels": [29.5, 45.5], "center": [-96, 37.8]})
m.enable_rtl_text_plugin()
m.set_mobile_behavior(cooperative_gestures=True, touch_zoom_rotate=False)

Feature Demonstrations

from maplibreum import (
    Map,
    Choropleth,
    Marker,
    MarkerCluster,
    LayerControl,
)

m = Map()

# Choropleth
Choropleth(geojson_data).add_to(m)

# Marker clusters
cluster = MarkerCluster().add_to(m)
Marker(coordinates=[0, 0]).add_to(cluster)

# Clustered GeoJSON
m.add_clustered_geojson(geojson_data)

# Layer controls
LayerControl().add_to(m)

Expressions

MapLibre uses array-based expressions for data-driven styling. The maplibreum.expressions module provides helpers to construct and validate these expressions:

from maplibreum.expressions import get, interpolate, var

color = interpolate(
    "linear",
    var("heatmap-density"),
    [(0, "blue"), (1, "red")],
)

Example Notebooks

jupyter notebook examples

View interactive examples deployed to GitHub Pages: MapLibreum Examples Gallery

The examples gallery is automatically generated from six progressive notebooks in the examples/ folder:

  • a polished first map and standalone HTML export;
  • data-driven accessibility styling;
  • decision-oriented choropleth mapping;
  • 3D terrain and PMTiles;
  • interaction that survives export without a Python kernel;
  • WebGL clustering for thousands of points.

The notebooks use deterministic teaching data, require no API keys, and are executed and rendered in CI. Maps that do not specify a style use the detailed OpenFreeMap Liberty basemap.

To deploy examples to GitHub Pages, see the GitHub Pages documentation.

Changelog

See the CHANGELOG for a detailed list of updates in each release.

Testing MapLibreum Functionality

Basic Testing

Run the core test suite to verify MapLibreum's basic functionality:

# Install development dependencies
pip install -e .
pip install pytest jupyter

# Run all basic tests
pytest tests/ -v

Advanced Testing: MapLibre Examples Validation

To verify that MapLibreum is working properly and to check feature coverage against MapLibre GL JS, use the comprehensive testing suite in development/maplibre_examples/:

MapLibre Examples Testing Suite

The development/maplibre_examples/ directory contains a systematic testing system that validates MapLibreum's capability to reproduce all official MapLibre GL JS examples. This provides:

  • Automated validation of feature coverage
  • Regression testing for new releases
  • Example conversion from JavaScript to Python
  • Performance benchmarking against reference implementations

Quick Status Check

# Install dependencies for the testing suite
pip install requests beautifulsoup4

# Check current implementation progress
python -c "
import json
with open('development/maplibre_examples/status.json') as f:
    data = json.load(f)
total = len(data)
implemented = sum(1 for v in data.values() if v['task_status'])
print(f'MapLibreum Feature Coverage: {implemented}/{total} ({implemented/total*100:.1f}%)')
print(f'Total MapLibre examples available: {total}')
print(f'Examples successfully implemented: {implemented}')
"

Running Example Tests

# Run all implemented example tests (when available)
pytest tests/test_examples/ -v

# Refresh examples from MapLibre.org (optional)
python development/maplibre_examples/scrapping.py

# Find next example to implement
python -c "
import json
with open('development/maplibre_examples/status.json') as f:
    data = json.load(f)
for name, info in data.items():
    if not info['task_status']:
        print(f'Next unimplemented example: {name}')
        print(f'MapLibre URL: {info[\"url\"]}')
        break
"

For detailed information about the testing suite, see the MapLibre examples testing guide.

Contributing

Contributions are welcome! Please see the issues page to see what needs to be done.

License

This project is licensed under the MIT License; see the LICENSE for details.

Metadata

Release files for maplibreum 0.2.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 maplibreum 0.2.3
File Size Uploaded Provenance Actions
maplibreum-0.2.3.tar.gz 120.5 kB With provenance Details for maplibreum-0.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 221.1 kB

Release files / maplibreum-0.2.3.tar.gz

Download URL maplibreum-0.2.3.tar.gz
Size 120.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c8e6c06317f4e73a4ca27c60022637daad70513253585b7ae04a993e819da624
BLAKE2b-256 checksum
How to use checksums
7ec2ac4451f5c78fa40b70cafe3c4b73ee57921c435954ed5fa43fea90a30b8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 28, 2026.

Transparency log

Release files / maplibreum-0.2.3-py3-none-any.whl

Download URL maplibreum-0.2.3-py3-none-any.whl
Size 100.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4397af600e0c8af2ab7532045f404ac3a234d263717e1703768626ef75ecf93e
BLAKE2b-256 checksum
How to use checksums
85e0a71a3d1757d7d12e9d80f176cb949d45011fdd5a690c7187141a06996abb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 28, 2026.

Transparency log

Security for maplibreum 0.2.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for maplibreum-0.2.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 Aug 28, 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.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files Full 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