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, 4 methods, zero confusion
  • Native Performance: Rust backend with MapLibre Native C++ core
  • No Runtime Dependencies: Bundled native binaries, no system libraries needed
  • Batch Rendering: Efficiently render hundreds of maps with one process
  • Mapbox-compatible: Easy migration from Mapbox Static Images API
  • Default OpenFreeMap: Uses Liberty style from OpenFreeMap by default

Installation

pip install mlnative

Platform-specific wheels include the native renderer binary:

  • Linux x86_64, aarch64
  • macOS x86_64, arm64 (Apple Silicon)
  • Windows x64

Quick Start

from mlnative import Map

# Render a single map
with Map(512, 512) as m:
    m.load_style("https://tiles.openfreemap.org/styles/liberty")
    png_bytes = m.render(center=[-122.4, 37.8], zoom=12)
    
    with open("map.png", "wb") as f:
        f.write(png_bytes)

API

Map(width, height, request_handler=None, pixel_ratio=1.0)

Create a new map renderer.

Parameters:

  • width: Image width in pixels (1-4096)
  • height: Image height in pixels (1-4096)
  • request_handler: Optional function for custom tile requests (not yet implemented)
  • pixel_ratio: Pixel ratio for high-DPI rendering

load_style(style)

Load a map style. Accepts:

  • URL string (http/https)
  • File path to JSON file
  • Style JSON dict

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

Render the map to PNG bytes.

Parameters:

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

Returns: PNG image bytes

render_batch(views)

Render multiple map views efficiently.

Parameters:

  • views: List of dicts with center, zoom, bearing, pitch keys

Returns: List of PNG image bytes

close()

Release resources. Called automatically with context manager.

Examples

Basic Usage

from mlnative import Map

# San Francisco
with Map(800, 600) as m:
    m.load_style("https://tiles.openfreemap.org/styles/liberty")
    png = m.render(
        center=[-122.4194, 37.7749],
        zoom=12,
        bearing=45,
        pitch=30
    )
    open("sf.png", "wb").write(png)

Batch Rendering

from mlnative import Map

views = [
    {"center": [0, 0], "zoom": 1},
    {"center": [10, 10], "zoom": 5},
    {"center": [-122.4, 37.8], "zoom": 12},
    # ... more views
]

with Map(512, 512) as m:
    m.load_style("https://tiles.openfreemap.org/styles/liberty")
    pngs = m.render_batch(views)
    
    for i, png in enumerate(pngs):
        with open(f"map_{i}.png", "wb") as f:
            f.write(png)

FastAPI Server

pip install mlnative[web]
python examples/fastapi_server.py

Then visit:

http://localhost:8000/static/-122.4194,37.7749,12/512x512.png

Supported Platforms

  • Linux x86_64, aarch64
  • macOS x86_64, arm64 (Apple Silicon)
  • Windows x64

Architecture

Python (mlnative) 
    ↓ JSON
Rust (mlnative-render daemon)
    ↓ FFI
MapLibre Native (C++ core with statically linked dependencies)

The native renderer uses pre-built "amalgam" libraries from MapLibre Native which include all dependencies (ICU, libjpeg, etc.) statically linked. This eliminates system dependency issues.

Development

Prerequisites

  • Python 3.12+
  • Rust toolchain (1.70+)
  • uv (Python package manager)

Setup

# Install Python dependencies
uv venv
uv pip install -e ".[dev,web]"

# Build Rust binary
cd rust && cargo build --release

Run Tests

just test

Build Wheels

# Local wheel (current platform only)
uv build

# All platforms (requires Docker)
just build-wheels

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.2.0a0.tar.gz (20.8 MB view details)

Uploaded Source

Built Distributions

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

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

Uploaded Python 3manylinux: glibc 2.28+ x86-64

mlnative-0.2.0a0-py3-none-any.whl (20.9 MB view details)

Uploaded Python 3

File details

Details for the file mlnative-0.2.0a0.tar.gz.

File metadata

  • Download URL: mlnative-0.2.0a0.tar.gz
  • Upload date:
  • Size: 20.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Bluefin","version":"43","id":"Deinonychus","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mlnative-0.2.0a0.tar.gz
Algorithm Hash digest
SHA256 1984e88d47243766fd1ed3bbd94c4d25790ee10b5e5729587df4d83cc1dc02c2
MD5 3a6a9331f496e93d4d1993d2cafa3d31
BLAKE2b-256 be4aed1aa2093c0232709f18fe834bd51bfe272dabad0daf781b8e1fd17a14d4

See more details on using hashes here.

File details

Details for the file mlnative-0.2.0a0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for mlnative-0.2.0a0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1956ac7e7877f4985198f9c7b61103f231ffc0a4e4f77ec943189778f9bef406
MD5 7bfdc86e05cb104e4451b53c3d4b5c31
BLAKE2b-256 588f6c1861d51483ea9409f04d6c32ee07483ab965ce9ee453304615f3300fed

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlnative-0.2.0a0-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.2.0a0-py3-none-any.whl.

File metadata

  • Download URL: mlnative-0.2.0a0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Bluefin","version":"43","id":"Deinonychus","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mlnative-0.2.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce9dfa16a274aa9ff5a27505e8e1f6e12c72aaa48e349e1cfa6358720a4b2fb8
MD5 40f21ded0ac32bd461403b91e6a1f810
BLAKE2b-256 cc4f46b911f3bd8ea1c30ac0d615e21602dd9ab62fc487babb33bb948af18d61

See more details on using hashes here.

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