A Python package for geospatial analysis and interactive mapping in a Jupyter environment.
npx @tessl/cli install tessl/pypi-leafmap@0.52.0A comprehensive Python package for geospatial analysis and interactive mapping designed specifically for Jupyter environments (Google Colab, Jupyter Notebook, JupyterLab, marimo). Built as a spin-off from the geemap project to serve non-Google Earth Engine users, it provides powerful geospatial capabilities through a minimal-coding approach with multiple backend support.
pip install leafmap or conda install -c conda-forge leafmapimport leafmap # Auto-selects backend based on environmentBackend Selection Logic: Leafmap automatically selects the appropriate backend:
leafmap.foliumap)leafmap.leafmap)Backend-specific imports:
import leafmap.leafmap as leafmap # ipyleaflet backend (default in Jupyter)
import leafmap.foliumap as leafmap # folium backend (default in Colab/marimo)
import leafmap.maplibregl as leafmap # MapLibre GL JS backend
import leafmap.plotlymap as leafmap # Plotly backend
import leafmap.deckgl as leafmap # lonboard/deck.gl backend
import leafmap.bokehmap as leafmap # bokeh backend
import leafmap.kepler as leafmap # kepler.gl backendUtility modules:
from leafmap import common # Core utility functions
from leafmap import basemaps # Basemap management
from leafmap import examples # Example datasets
from leafmap import stac # STAC catalog functions
from leafmap import osm # OpenStreetMap functionsimport leafmap
# Create an interactive map (backend auto-selected based on environment)
m = leafmap.Map(center=[40, -100], zoom=4)
# Add a basemap
m.add_basemap('OpenTopoMap')
# Add vector data
m.add_vector('path/to/vector.shp', layer_name='Vector Layer')
# Add raster data
m.add_raster('path/to/raster.tif', colormap='terrain', layer_name='Raster Layer')
# Add online data sources
m.add_cog_layer('https://example.com/data.tif', name='COG Layer')
# Display the map
mLeafmap uses a multi-backend architecture that automatically selects the appropriate mapping framework based on the runtime environment:
The package integrates with numerous geospatial libraries and services including folium, ipyleaflet, bokeh, kepler.gl, pydeck, plotly, maplibre, WhiteboxTools, and cloud data providers.
Core map functionality with multiple backend support including ipyleaflet, folium, MapLibre GL JS, Plotly, Bokeh, Kepler.gl, HERE Maps, Mapbox, and lonboard. Provides automatic backend selection based on environment.
class Map:
def __init__(self, center=[20, 0], zoom=2, basemap='HYBRID', **kwargs): ...
def add_basemap(self, basemap='HYBRID', show=True, **kwargs): ...
def add_layer_control(self, position='topright', **kwargs): ...Comprehensive data visualization capabilities for vector and raster data, including shapefiles, GeoJSON, COG, STAC, and various online data sources with customizable styling and interactive features.
def add_vector(self, filename, layer_name='Untitled', **kwargs): ...
def add_raster(self, image, colormap=None, vmin=None, vmax=None, **kwargs): ...
def add_cog_layer(self, url, name='Untitled', **kwargs): ...
def add_geojson(self, data, layer_name='Untitled', **kwargs): ...Advanced geospatial analysis tools including zonal statistics, clipping, mosaicking, reprojection, and integration with WhiteboxTools for comprehensive analytical capabilities.
def zonal_stats(image, zones, stats=['count', 'mean', 'std'], **kwargs): ...
def clip_image(image, mask, output=None, **kwargs): ...
def mosaic(images, output=None, **kwargs): ...
def reproject(image, crs, output=None, **kwargs): ...Integration with major cloud data providers and services including Microsoft Planetary Computer, Google Earth Engine, NASA datasets, Planet Labs, AWS Open Data, and STAC catalogs.
def stac_search(collection, bbox, time_range=None, **kwargs): ...
def add_stac_layer(self, url, collection, item, **kwargs): ...
def get_pc_collections(): ...
def nasa_data_search(dataset, **kwargs): ...Extensive basemap collection with 100+ predefined providers supporting XYZ tiles, WMS services, and custom tile sources with backend-specific optimizations.
def get_xyz_dict(free_only=True, france=False): ...
def xyz_to_leaflet(): ...
def search_qms(keyword): ...
XYZ_TILES: dict # Built-in basemap providers (100+ total with xyzservices integration)Comprehensive file input/output capabilities supporting various geospatial formats, coordinate transformations, and data conversion utilities for seamless data workflows.
def download_file(url, filename, **kwargs): ...
def read_raster(filename, **kwargs): ...
def read_vector(filename, **kwargs): ...
def csv_to_geojson(filename, **kwargs): ...Direct integration with OpenStreetMap data through the Overpass API, enabling querying and visualization of OSM data by address, place, bounding box, or point with tag-based filtering.
def osm_gdf_from_address(address, tags, **kwargs): ...
def osm_gdf_from_bbox(bbox, tags, **kwargs): ...
def osm_tags_list(): ...Interactive statistical plotting capabilities using Plotly for creating bar charts, line charts, histograms, and pie charts integrated with geospatial data workflows.
def bar_chart(data, x, y, **kwargs): ...
def line_chart(data, x, y, **kwargs): ...
def histogram(data, column, **kwargs): ...def view_vector(vector, zoom_to_layer=True, pickable=True, color_column=None,
color_scheme="Quantiles", color_map=None, color_k=5,
color_args={}, open_args={}, map_args={}, **kwargs):
"""
Quick visualization of vector data using lonboard/deck.gl backend.
Args:
vector (Union[str, GeoDataFrame]): Path to vector file or GeoDataFrame
zoom_to_layer (bool): Flag to zoom to the added layer
pickable (bool): Flag to enable picking on the added layer
color_column (str): Column to be used for color encoding
color_scheme (str): Color scheme for classification ("Quantiles", "EqualInterval", etc.)
color_map (Union[str, Dict]): Color map for encoding
color_k (int): Number of classes for color encoding
color_args (dict): Additional arguments for assign_continuous_colors()
open_args (dict): Additional arguments for geopandas.read_file()
map_args (dict): Additional arguments for lonboard.Map
**kwargs: Additional arguments for lonboard.Layer.from_geopandas()
Returns:
lonboard.Map: A lonboard Map object
"""
def view_pmtiles(url, style=None, name=None, tooltip=True, overlay=True,
control=True, show=True, zoom_to_layer=True, map_args={}, **kwargs):
"""
Quick visualization of PMTiles data using folium backend.
Args:
url (str): URL to PMTiles file
style (str): CSS style to apply to the layer
name (str): Name of the layer
tooltip (bool): Whether to show tooltip when hovering
overlay (bool): Whether the layer should be added as overlay
control (bool): Whether to include layer in layer control
show (bool): Whether the layer should be shown initially
zoom_to_layer (bool): Whether to zoom to layer extent
map_args (dict): Additional arguments for folium.Map
**kwargs: Additional arguments for PMTilesLayer constructor
Returns:
folium.Map: A folium Map object
"""# Coordinate reference system specification
CRS = Union[str, int, pyproj.CRS]
# Bounding box as [minx, miny, maxx, maxy]
BBox = List[float]
# Coordinate pairs [latitude, longitude] or [y, x]
Coordinates = Union[List[float], Tuple[float, float]]
# Color specification for styling
Color = Union[str, Tuple[int, int, int], Tuple[int, int, int, int]]
# Geometry types supported
Geometry = Union[dict, shapely.geometry.base.BaseGeometry]
# Data source types
DataSource = Union[str, pathlib.Path, gpd.GeoDataFrame, dict]
# Layer objects for different backends
Layer = Union[ipyleaflet.Layer, folium.Layer, dict]
# Style dictionary for vector styling
StyleDict = Dict[str, Union[str, int, float, bool]]
# Tags dictionary for OSM queries
OSMTags = Dict[str, Union[str, bool, List[str]]]
# Map widget options
MapOptions = Dict[str, Union[str, int, float, bool, List, Tuple]]
# Time range specification
TimeRange = Union[List[str], Tuple[str, str]]
# Search results from STAC/catalog queries
SearchResults = List[Dict[str, Any]]