Dynamic vector tile server for visualizing vectors in Jupyter notebooks
Project description
🌐 vectortileserver
A local vector tile server for visualizing PMTiles in Jupyter — localtileserver, but for vectors. Inspired by localtileserver, leafmap, protomaps-leaflet and maplibre-gl.
With TileClient, you can easily create a local vector tile server to visualize PMTiles in ipyleaflet.
If you have a vector file (.shp, .geojson, .gpkg, etc.), TileClient will convert it to PMTiles format using tippecanoe. If tippecanoe is not installed, an error will be raised. However, you can directly visualize local PMTiles as a data source.
Installation
The quickest way to get everything — the package, its dependencies, and tippecanoe — is the bundled conda/micromamba environment:
micromamba env create -f environment.yml # or: conda env create -f environment.yml
micromamba activate vectortileserver
Or install with pip and provide tippecanoe yourself (see Installing Tippecanoe):
pip install vectortileserver
Demo
examples/demo.ipynb builds a point layer end to end and doubles as a bridge test. Open it in JupyterLab, or serve it with Voila to confirm tiles load in a sandboxed webview (watch the Network tab for the absence of direct 127.0.0.1 requests):
jupyter lab examples/demo.ipynb
voila examples/demo.ipynb
Usage
from ipyleaflet import Map
from vectortileserver import TileClient
client = TileClient("points.geojson") # converts to points.pmtiles
m = Map(center=client.center, zoom=10)
m.add(client.create_leaflet_layer())
m
A conversion is reused as long as the .pmtiles file is at least as new as its source and was built with the same conversion_options — the options are recorded in a <name>.pmtiles.json sidecar. Edit the source or change the options and the next TileClient reconverts. Delete the .pmtiles to force a rebuild.
Layer-first API (recommended)
import vectortileserver as vts
from ipyleaflet import Map
m = Map()
layer = await vts.open_async("data.geojson") # convert off-thread → ready layer
m.add(layer)
if layer.bounds: # None for a point/degenerate archive
m.fit_bounds(layer.bounds) # zoom to the layer's own bounds
# many datasets, in parallel:
for layer in await vts.open_many(["a.geojson", "b.shp"]):
m.add(layer)
bounds = vts.default_workspace().bounds() # union of everything opened (None if none bounded)
if bounds:
m.fit_bounds(bounds)
open_async runs tippecanoe on a worker thread and returns a VectorTileLayer
(an ipyleaflet PMTilesLayer) that carries .bounds ([[S,W],[N,E]]),
.center, and .list_layers(). Style it with a builder — vts.default_style,
vts.single_symbol_style(color=...), or vts.categorized_style(field, values) —
and restyle by swapping layer.with_style(...). For advanced control (explicit
lifecycle, isolation), construct a vts.TileWorkspace. The classic
TileClient API keeps working unchanged.
Point retention
Tippecanoe is tuned for basemaps: below its computed base zoom it keeps only a fraction of the features per level, and it discards whatever else is needed to stay under 200k features and 500KB per tile. For a point layer that is silent data loss — 200 points can render as 1 at zoom 0.
This package therefore converts with retention on by default:
--drop-rate 1 --no-feature-limit --no-tile-size-limit
Override any of them through conversion_options, which is passed straight to tippecanoe. Keys become flags (no_feature_limit → --no-feature-limit), True renders a bare flag, and False or None removes it:
# Get tippecanoe's thinning back for a dense layer
TileClient("dense.geojson", conversion_options={"drop_rate": 2.5})
# Or drop a single default
TileClient("dense.geojson", conversion_options={"no_tile_size_limit": False})
The defaults live in vectortileserver.converter.DEFAULT_CONVERSION_OPTIONS.
Notebook frontends
Tiles are fetched by the browser, which in many frontends cannot reach the kernel's http://localhost:<port> directly. vectortileserver tunnels them over the kernel's own comm channel with jupyter-loopback: create_leaflet_layer() installs the bridge automatically (once per port), and the same path works in JupyterLab, Notebook 7, Voila, SEPAL, VS Code Jupyter, and Colab. HTTP Range requests and 206 Partial Content — what PMTiles relies on — survive the trip.
| Environment variable | Effect |
|---|---|
VECTORTILESERVER_DISABLE_JUPYTER_LOOPBACK=1 |
Never install the comm bridge. |
VECTORTILESERVER_CLIENT_PREFIX |
Route tile URLs through a reverse proxy you run — a root-relative path (/user/alice/tiles/{port}) or a full URL (https://host/tiles/{port}); {port} is substituted. An empty value forces the default http://localhost:<port> URLs. |
To bridge a port yourself:
client.server_port # the loopback port
client.enable_jupyter_loopback() # idempotent
Installing Tippecanoe
The bundled environment.yml already installs tippecanoe from conda-forge, so if you created the environment above you can skip this section.
Tippecanoe is a tool for generating vector tile sets from large collections of GeoJSON features. It is designed to make mapping large datasets easy and efficient.
git clone https://github.com/felt/tippecanoe.git
cd tippecanoe
make -j
make install
Or from conda-forge:
conda install -c conda-forge tippecanoe
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vectortileserver-0.2.0.tar.gz.
File metadata
- Download URL: vectortileserver-0.2.0.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e51caa1b6f26ce3a673486aee4077253d4b881ee3f27400b4d8acc6ad8e1768c
|
|
| MD5 |
779cec79634d98f106b49880cb0c2a1d
|
|
| BLAKE2b-256 |
2b92fa55110b8c0e6ec8286febeadb95f1255fe04c15a139c220fbc779b8122e
|
Provenance
The following attestation bundles were made for vectortileserver-0.2.0.tar.gz:
Publisher:
release.yml on dfguerrerom/vectortileserver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vectortileserver-0.2.0.tar.gz -
Subject digest:
e51caa1b6f26ce3a673486aee4077253d4b881ee3f27400b4d8acc6ad8e1768c - Sigstore transparency entry: 2257380783
- Sigstore integration time:
-
Permalink:
dfguerrerom/vectortileserver@231974e3e65c48456e79d7231308f831db59b09a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dfguerrerom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@231974e3e65c48456e79d7231308f831db59b09a -
Trigger Event:
release
-
Statement type:
File details
Details for the file vectortileserver-0.2.0-py3-none-any.whl.
File metadata
- Download URL: vectortileserver-0.2.0-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d1757dde6f5d93b9fbcc718d8533e6f0efe8309bb157cbe88382106011d42d3
|
|
| MD5 |
a0ec7b1f1071a918d5cb5253ceb2fc3a
|
|
| BLAKE2b-256 |
40c68543703910f9413f0b7febd5c689d20518f5c3f1a0b62030f0ff68f811fa
|
Provenance
The following attestation bundles were made for vectortileserver-0.2.0-py3-none-any.whl:
Publisher:
release.yml on dfguerrerom/vectortileserver
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vectortileserver-0.2.0-py3-none-any.whl -
Subject digest:
7d1757dde6f5d93b9fbcc718d8533e6f0efe8309bb157cbe88382106011d42d3 - Sigstore transparency entry: 2257380796
- Sigstore integration time:
-
Permalink:
dfguerrerom/vectortileserver@231974e3e65c48456e79d7231308f831db59b09a -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/dfguerrerom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@231974e3e65c48456e79d7231308f831db59b09a -
Trigger Event:
release
-
Statement type: