Skip to main content

A lightweight PostGIS based dynamic vector tile server.

Project description

A lightweight PostGIS based dynamic vector tile server.

Test Coverage Package version License


Documentation: https://developmentseed.org/timvt/

Source Code: https://github.com/developmentseed/timvt


:warning: This project is on pause while we focus on developmentseed/tipg :warning:

ref: https://github.com/developmentseed/timvt/discussions/96


TiMVT, pronounced tee-MVT, is a python package which helps creating lightweight Vector Tiles service from PostGIS Database.

Built on top of the modern and fast FastAPI framework, timvt is written in Python using async/await asynchronous code to improve the performances and handle heavy loads.

TiMVT is mostly inspired from the awesome urbica/martin and CrunchyData/pg_tileserv projects.

Features

  • Multiple TileMatrixSets via morecantile. Default is set to WebMercatorQuad which is the usual Web Mercator projection used in most of Wep Map libraries.)
  • Built with FastAPI
  • Table and Function layers
  • Async API using asyncpg

Install

Install TiMVT from pypi

# update pip (optional)
python -m pip install pip -U

# install timvt
python -m pip install timvt

or install from source:

$ git clone https://github.com/developmentseed/timvt.git
$ cd timvt
$ python -m pip install -e .

PostGIS/Postgres

TiMVT rely mostly on ST_AsMVT function and will need PostGIS >= 2.5.

If you want more info about ST_AsMVT function or on the subject of creating Vector Tile from PostGIS, please read this great article from Paul Ramsey: https://info.crunchydata.com/blog/dynamic-vector-tiles-from-postgis

Configuration

To be able to create Vector Tile, the application will need access to the PostGIS database. TiMVT uses pydantic's configuration pattern which make use of environment variable and/or .env file to pass variable to the application.

Example of .env file can be found in .env.example

POSTGRES_USER=username
POSTGRES_PASS=password
POSTGRES_DBNAME=postgis
POSTGRES_HOST=0.0.0.0
POSTGRES_PORT=5432

# Or you can also define the DATABASE_URL directly
DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis

Minimal Application

from timvt.db import close_db_connection, connect_to_db
from timvt.factory import VectorTilerFactory
from timvt.layer import FunctionRegistry
from fastapi import FastAPI, Request

# Create Application.
app = FastAPI()

# Add Function registry to the application state
app.state.timvt_function_catalog = FunctionRegistry()

# Register Start/Stop application event handler to setup/stop the database connection
# and populate `app.state.table_catalog`
@app.on_event("startup")
async def startup_event():
    """Application startup: register the database connection and create table list."""
    await connect_to_db(app)


@app.on_event("shutdown")
async def shutdown_event():
    """Application shutdown: de-register the database connection."""
    await close_db_connection(app)

# Register endpoints.
mvt_tiler = VectorTilerFactory(
    with_tables_metadata=True,
    with_functions_metadata=True,  # add Functions metadata endpoints (/functions.json, /{function_name}.json)
    with_viewer=True,
)
app.include_router(mvt_tiler.router, tags=["Tiles"])

Default Application

While we encourage users to write their own application using TiMVT package, we also provide a default production ready application:

# Install timvt dependencies and Uvicorn (a lightning-fast ASGI server)
$ pip install timvt 'uvicorn[standard]>=0.12.0,<0.14.0'

# Set Database URL environment variable so TiMVT can access it
$ export DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis

# Launch Demo Application
$ uvicorn timvt.main:app --reload

You can also use the official docker image

$ docker run \
    -p 8081:8081 \
    -e PORT=8081 \
    -e DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis \
    ghcr.io/developmentseed/timvt:latest

:endpoint:/docs

Contribution & Development

See CONTRIBUTING.md

License

See LICENSE

Authors

Created by Development Seed

Changes

See CHANGES.md.

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

timvt-0.8.0a3.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

timvt-0.8.0a3-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file timvt-0.8.0a3.tar.gz.

File metadata

  • Download URL: timvt-0.8.0a3.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for timvt-0.8.0a3.tar.gz
Algorithm Hash digest
SHA256 db87408a0132836fae976edf7e973ed7f87ccc5f32ece699ecb52f5d85ccb261
MD5 bc22d66b6b2c248533df6b9d2bf4ee59
BLAKE2b-256 623dcc59468b30b99524fab23e2bd2656976b49129242d7daca67a2dbcdc6398

See more details on using hashes here.

File details

Details for the file timvt-0.8.0a3-py3-none-any.whl.

File metadata

  • Download URL: timvt-0.8.0a3-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for timvt-0.8.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 886579d92ef980ff227ed722e5fd88c13f8984dc73fa2b343125e8edc5537821
MD5 3ff4b7edd3fa788f694c1f7c3cdc527c
BLAKE2b-256 f52aca46d6e300893e178750ecd32981e8061d619190f970df90faa7ca030594

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page