Skip to main content

Simple Python wrapper for MapLibre GL Native using native Rust renderer

Project description

mlnative ⚠️ ALPHA RELEASE

⚠️ Warning: This is an alpha release (v0.2.0-alpha). The API may change significantly. Not recommended for production use.

Simple Python wrapper for MapLibre GL Native using a native Rust renderer.

A grug-brained library for rendering static map images with minimal complexity.

Features

  • Simple API: One class, minimal methods, zero confusion
  • Native Performance: Rust backend with MapLibre Native C++ core
  • Built-in Defaults: Uses OpenFreeMap Liberty style by default - no configuration needed
  • Address Support: Built-in geocoding with geopy for rendering addresses directly
  • Geometry Support: Shapely integration for bounds fitting and GeoJSON

Installation

pip install mlnative

Platform-specific wheels include the native renderer binary:

  • Linux x86_64, aarch64

Quick Start

from mlnative import Map

# Render a map - uses OpenFreeMap Liberty style by default
with Map(512, 512) as m:
    png_bytes = m.render(center=[-122.4, 37.8], zoom=12)
    
    with open("map.png", "wb") as f:
        f.write(png_bytes)

Rendering from Addresses

from mlnative import Map
from geopy.geocoders import ArcGIS

# Geocode an address and render
geolocator = ArcGIS()
location = geolocator.geocode("Sydney Opera House")

with Map(512, 512) as m:
    png = m.render(
        center=[location.longitude, location.latitude],
        zoom=16
    )
    open("sydney.png", "wb").write(png)

Custom Styles

While OpenFreeMap Liberty is the default, you can override it:

# Load a different style
m.load_style("https://example.com/style.json")

# Or load from dict
m.load_style({"version": 8, "sources": {...}, "layers": [...]})

API Reference

Map Class

Map(width, height, pixel_ratio=1.0)

Create a new map renderer.

  • width: Image width in pixels (1-4096)
  • height: Image height in pixels (1-4096)
  • pixel_ratio: Pixel ratio for high-DPI rendering

render(center, zoom, bearing=0, pitch=0)

Render the map to PNG bytes. Uses OpenFreeMap Liberty style by default.

  • center: [longitude, latitude] list
  • zoom: Zoom level (0-24)
  • bearing: Rotation in degrees (0-360)
  • pitch: Tilt in degrees (0-85)

render_batch(views)

Render multiple views efficiently.

fit_bounds(bounds, padding=0, max_zoom=24)

Calculate center/zoom to fit bounds. Returns (center, zoom).

bounds = (-122.6, 37.7, -122.3, 37.9)  # (xmin, ymin, xmax, ymax)
center, zoom = m.fit_bounds(bounds)
png = m.render(center=center, zoom=zoom)

set_geojson(source_id, geojson)

Update GeoJSON source data (requires style loaded as dict).

from shapely import Point
m.set_geojson("markers", Point(-122.4, 37.8))

load_style(style)

Load custom style (URL, file path, or dict). Call before render if not using default.

GeoJSON Helpers

from mlnative import point, feature_collection, from_coordinates, from_latlng

# From coordinates (lng, lat)
fc = from_coordinates([(-122.4, 37.8), (-74.0, 40.7)])

# From GPS coordinates (lat, lng)  
fc = from_latlng([(37.8, -122.4), (40.7, -74.0)])

# From shapely
from shapely import MultiPoint, Point
fc = feature_collection(MultiPoint([Point(-122.4, 37.8), Point(-74.0, 40.7)]))

Examples

See examples/ directory:

  • basic.py - Simple usage
  • address_rendering.py - Render from addresses
  • fastapi_server.py - Static maps API

Supported Platforms

  • Linux x86_64, aarch64

Note: macOS and Windows support limited due to upstream MapLibre Native build constraints.

Development

Requires Python 3.12+, Rust 1.70+, and uv.

# Setup
uv pip install -e ".[dev,web]"
cd rust && cargo build --release

# Run tests
just test

License

Apache-2.0

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

mlnative-0.3.0.tar.gz (70.4 kB view details)

Uploaded Source

Built Distribution

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

mlnative-0.3.0-py3-none-manylinux_2_28_x86_64.whl (20.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

File details

Details for the file mlnative-0.3.0.tar.gz.

File metadata

  • Download URL: mlnative-0.3.0.tar.gz
  • Upload date:
  • Size: 70.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mlnative-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d04dc29e959f0e30e46fc08601ad3c1b7a3fe5f7f1faff360f1b4b96b7604598
MD5 af98a62c8f0c619934f9da4fec9b8931
BLAKE2b-256 063ccc65df33046931e02c5ed44b8a65d97f918001712c7157c4db0ba46d1cb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.3.0.tar.gz:

Publisher: release.yml on adonm/mlnative

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

File details

Details for the file mlnative-0.3.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mlnative-0.3.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d90de68ab79d7fec7139d748aacc92dacc2727e8f8fc0ebd58f061ab868fda6
MD5 f36c765a31536d56a793ef269fc077b5
BLAKE2b-256 0253424eca2233af56d891d901dfef3b9a77c4debe1e771977ed86a92a287a5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.3.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release.yml on adonm/mlnative

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