Package: timvt
A lightweight PostGIS based dynamic vector tile server.Documentation:https://developmentseed.org/timvt/Source Code:https://github.com/developmentseed/timvtTiMVT, pronouncedtee-MVT, is a python package which helps creating lightweightVector Tilesservice fromPostGISDatabase.Built on top of themodern and fastFastAPIframework, timvt is written in Python using async/await asynchronous code to improve the performances and handle heavy loads.TiMVTis mostly inspired from the awesomeurbica/martinandCrunchyData/pg_tileservprojects.FeaturesMultiple TileMatrixSets viamorecantile. Default is set to WebMercatorQuad which is the usual Web Mercator projection used in most of Wep Map libraries.)Built withFastAPITable and Function layersAsync API usingasyncpgInstallInstallTiMVTfrom pypi# update pip (optional)python-mpipinstallpip-U# install timvtpython-mpipinstalltimvtor install from source:$gitclonehttps://github.com/developmentseed/timvt.git
$cdtimvt
$python-mpipinstall-e.PostGIS/PostgresTiMVTrely mostly onST_AsMVTfunction and will need PostGIS >= 2.5.If you want more info aboutST_AsMVTfunction 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-postgisConfigurationTo be able to create Vector Tile, the application will need access to the PostGIS database.TiMVTusespydantic's configuration pattern which make use of environment variable and/or.envfile to pass variable to the application.Example of.envfile can be found in.env.examplePOSTGRES_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/postgisMinimal Applicationfromtimvt.dbimportclose_db_connection,connect_to_dbfromtimvt.factoryimportVectorTilerFactoryfromtimvt.layerimportFunctionRegistryfromfastapiimportFastAPI,Request# Create Application.app=FastAPI()# Add Function registry to the application stateapp.state.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")asyncdefstartup_event():"""Application startup: register the database connection and create table list."""awaitconnect_to_db(app)@app.on_event("shutdown")asyncdefshutdown_event():"""Application shutdown: de-register the database connection."""awaitclose_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 ApplicationWhile we encourage users to write their own application usingTiMVTpackage, we also provide a defaultproduction readyapplication:# Install timvt dependencies and Uvicorn (a lightning-fast ASGI server)$pipinstalltimvt'uvicorn[standard]>=0.12.0,<0.14.0'# Set Database URL environment variable so TiMVT can access it$exportDATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis# Launch Demo Application$uvicorntimvt.main:app--reloadYou 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:/docsContribution & DevelopmentSeeCONTRIBUTING.mdLicenseSeeLICENSEAuthorsCreated byDevelopment SeedChangesSeeCHANGES.md.