ml2drender (Python)
Python bindings of ml2drender, a 2D map renderer for MapLibre styles written in pure Rust. It needs no GPU and links no C libraries.
pip install ml2drender
Wheels are built for Linux (x86-64, arm64; glibc), macOS (x86-64, arm64) and Windows (x86-64), for CPython 3.11 and later (abi3).
Usage
The renderer does no I/O. It asks for the resources a style needs (TileJSON, GeoJSON, sprites, tiles, glyph ranges) and you load them. render runs that loop with a load function:
import json
import urllib.error
import urllib.request
import ml2drender
def load(url):
try:
with urllib.request.urlopen(url) as response:
return response.read()
except urllib.error.HTTPError as e:
if e.code == 404:
return None # missing: an empty vector tile, a raster tile replaced by its parent
raise
style = load("https://demotiles.maplibre.org/style.json").decode()
view = ml2drender.View.tile(5, 28, 12, tile_size=512)
# or a camera: ml2drender.View((139.767, 35.681), zoom=5, width=512, height=512, bearing=0)
rgba = ml2drender.render(style, view, load)
width, height = view.size
open("tile.png", "wb").write(ml2drender.encode_png(rgba, width, height))
Resource URLs reach load exactly as the style writes them, so make glyphs, sprite and TileJSON URLs absolute. load should return None only for a missing resource; raise for other failures (the exception propagates out of render).
To load concurrently (for example with asyncio or a thread pool), drive the steps yourself. Resources come in stages, each found from the last, so repeat until nothing is needed:
from concurrent.futures import ThreadPoolExecutor
renderer = ml2drender.Renderer(style, view)
with ThreadPoolExecutor(16) as pool:
while urls := renderer.needs():
for url, data in zip(urls, pool.map(load, urls)):
renderer.provide(url, data)
rgba = renderer.render()
A Renderer keeps what it has loaded: set_view points it at another camera and the next needs asks only for what is missing.
API
View(center, zoom, width, height, bearing=0.0, pixel_ratio=1.0, margin=0) |
A Web Mercator camera. center is (lng, lat) in degrees; zoom is the MapLibre zoom (the world is 512 * 2**zoom CSS pixels wide); bearing is degrees clockwise. The image is width x height CSS pixels, times pixel_ratio in pixels. margin CSS pixels are drawn around it and cropped, so labels near the edge are placed as in a larger map. |
View.tile(z, x, y, tile_size=256) |
The XYZ tile z/x/y, tile_size CSS pixels square. |
View.size |
(width, height) of the output in pixels. |
render(style, view, load) |
Non-premultiplied RGBA8 pixels (bytes, row by row) of style (a JSON string) in view. |
Renderer(style, view) |
The steps of render: needs() -> list[str], provide(url, data: bytes | None), render() -> bytes, set_view(view). Not thread-safe. |
encode_png(rgba, width, height) |
Lossless PNG. |
encode_webp(rgba, width, height) |
Lossless WebP. |
encode_jpeg(rgba, width, height, quality=90) |
JPEG, flattened over black. |
Invalid styles and rendering errors raise RuntimeError. Type hints and docstrings ship with the package (ml2drender.pyi).
The Python bindings draw Web Mercator views only. Projected CRSs (PROJJSON), reprojected sources for MapLibre GL JS and resource fetching are in the JavaScript package.
License
BSD-3-Clause
Metadata
Release files for ml2drender 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ml2drender-0.1.0.tar.gz | 241.6 kB | With provenance | Details for ml2drender-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| ml2drender-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for ml2drender-0.1.0-cp311-abi3-win_amd64.whl |
| ml2drender-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for ml2drender-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| ml2drender-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for ml2drender-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| ml2drender-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for ml2drender-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
| ml2drender-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details for ml2drender-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
Total release size: 6.9 MB
Release files / ml2drender-0.1.0.tar.gz
| Download URL | ml2drender-0.1.0.tar.gz |
|---|---|
| Size | 241.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5d290becf75597503fb1195a29a269c77e559d3a77bf225c7e0bbad3c74e532
|
|
BLAKE2b-256 checksum How to use checksums |
3b5776fc098f708d836846dafd7f3541b9784b66b3ccb0ef244a9830ccfbfd2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / ml2drender-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | ml2drender-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
de332dcccfee4270aa43eec5778005172ff41293669ab8fd90ccdb408835e889
|
|
BLAKE2b-256 checksum How to use checksums |
c8c8b02345830ad237ae20f5b9a750684bf2bb62eda6c70d5a820174609ff337
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / ml2drender-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | ml2drender-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2307d4adfeaaf09886d88050dcdd8e82ff8b52c0a1c6bc307c8ac259ecbf95a2
|
|
BLAKE2b-256 checksum How to use checksums |
4e3e56b1dc58b71e30bb6fd4380c82609e31848c8c6aaabe58b418896498f581
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / ml2drender-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | ml2drender-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
c58f2582b33e9fcb04a8b68517a3c21c5aeb5b62bb6411b3cb0c0626468bab14
|
|
BLAKE2b-256 checksum How to use checksums |
2225e871cf625020b9a71cbad0abe4feef01443947d511b89c1cf98382de085f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / ml2drender-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | ml2drender-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c33c0b371b7c998331cb880ff1ebd10f2319d1bdacfa0c79246f4f62fb7617af
|
|
BLAKE2b-256 checksum How to use checksums |
d7e4ba5c4051e396234a09252aaabf5488a57c2ff30e8caeceed5859b2dba529
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logRelease files / ml2drender-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | ml2drender-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
047f32614c9f7bd95cb619c35488b5e28b2140c0707e51f145fc04e035716fbb
|
|
BLAKE2b-256 checksum How to use checksums |
6e69f60b4472da123bf83759270e9df5e8e7920386db3fc47f9582b28073c83e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 15, 2026.
Transparency logSecurity for ml2drender 0.1.0
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
All 6 files in this release have been uploaded with provenance metadata.
Attestation for ml2drender-0.1.0.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 Nov 15, 2026.
Transparency logA 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.