Skip to content

zellige/python-mbtiles-server

Repository files navigation

python-mbtiles-server

The simple mbtiles server is a quick and easy way to get starting with the mapbox vector tiles ecosystem in python.

The server can serve a file built using tippecanoe.

With the "browser" option, the server will open a web page where you can view the tile layers in the mbtiles file on a simple map.

Getting Started

At this stage, its a "build your own" kinda deal, but I have plans to make some releases for various platforms soon.

To set up, first clone this repo:

git clone git@github.com:zellige/python-mbtiles-server.git"
cd python-mbtiles-server

Installation

pip install python-mbtiles-server

Basic Usage

1. Direct Python Integration

from python_mbtiles_server.server import create_app
from fastapi import FastAPI
from pathlib import Path

def setup_tile_server(mbtiles_path: str) -> FastAPI:
    """Create a tile server for SCRAM data"""
    app = create_app(
        mbtiles_path=Path(mbtiles_path),
        static_dir=None  # Optional: Add static files if needed
    )
    return app

# Example usage
app = setup_tile_server("path/to/scram/links.mbtiles")

2. Command Line Usage

For development and testing:

python -m simple_mbtiles_server.cli path/to/scram/links.mbtiles --port 8765

Code formating

Use Ormolu: https://github.com/tweag/ormolu

Content Encoding

By default, Tippecanoe produces gzipped tiles. This causes a Unimplimented type: 3 error if the content-encoding header on the response is not set correctly.

Simple mbtiles uses the "generator_opts" field in the tile metadata to determine whether the last generator command included the -pC option to produce uncompressed tiles (see Tippecanoe readme for explanation). If if did, it will set content encoding to "identity" or uncompressed. Otherwise, it will set "gzip" as the content encoding.

About

Direct python form of simple-mbtiles-server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages