Skip to main content

Simple Python wrapper for MapLibre GL Native using native Rust renderer

Project description

mlnative

PyPI version License

⚠️ Warning: This is an alpha release. 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=15  # Good for landmark/building view
    )
    open("sydney.png", "wb").write(png)

Custom Styles

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

# OpenFreeMap styles
m.load_style("https://tiles.openfreemap.org/styles/liberty")
m.load_style("https://tiles.openfreemap.org/styles/positron")
m.load_style("https://tiles.openfreemap.org/styles/dark")

# MapLibre demo tiles (good for testing)
m.load_style("https://demotiles.maplibre.org/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.1.tar.gz (70.6 kB view details)

Uploaded Source

Built Distributions

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

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

mlnative-0.3.1-py3-none-manylinux_2_28_aarch64.whl (20.5 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

File details

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

File metadata

  • Download URL: mlnative-0.3.1.tar.gz
  • Upload date:
  • Size: 70.6 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.1.tar.gz
Algorithm Hash digest
SHA256 f0a1325d8d94a48478e5597ac69910c4b52bc2a2e0ff6b2e6d43a1d01320e437
MD5 13f018815fea638044a469c21b484cd4
BLAKE2b-256 450e2ccb5ea4290454a2448734aa2efe0fb0f7f3231a79d075b4c5b9bcdfda27

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.3.1.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.1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mlnative-0.3.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5fcf349de932cb9061dd5f21273f9739527dcb95320bb4d3aceafc93dca708f2
MD5 a2c4788632a215a7ea2d95fffb62b51a
BLAKE2b-256 0a84b3cb95217cc139e1c4ea89fb95249b80cfcea72ee8c841496bbaf7e51c15

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.3.1-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.

File details

Details for the file mlnative-0.3.1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for mlnative-0.3.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 469d4f217805a627c96e57e81e5857fc89c2d5d296bccd850223d39869c039c4
MD5 3da8684ee878449743accaf776d6364e
BLAKE2b-256 9ddf6da6e387f28f76dd04f8178f6c29ce02b13c8932c105d74447926d228792

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.3.1-py3-none-manylinux_2_28_aarch64.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