postpass-formatter

May 17, 2026 ยท View on GitHub

A Python WSGI script that wraps around a local Postpass instance and converts the output into various formats using the Jinja templating library.

Running it

You can run this standalone on port 8001 with

python3 formatter.py

or you can run it from Apachae mod_wsgi with a line like

WSGIScriptAlias /formatter /path/to/repo/wsgi.py

Using it

Simply send a HTTP POST request with your PostGIS query in the data parameter (just like you would with plain Postpass), and additionally specify a format parameter with the desired output format.

Supported formats

  • geojson: (default if not defined) single GeoJSON FeatureCollection. If each row doesn't have a geometry column, a HTTP 400 will be returned.
  • html_table: A table in HTML
    <table>
    <thead><th>count</th><th>is_null</th></thead>
    <tr><td>141183</td><td>false</td></tr>
    <tr><td>2404499</td><td>true</td></tr>
    </table>
    
  • md_table: A table in Markdown
    | count   | is_null |
    |---------|---------|
    | 141183  | false   |
    | 2404499 | true    |
    
  • csv: Comma Separated Values
    "count","is_null"
    141183,"false"
    2404499,"true"
    
  • csv_headerless: Comma Separated Values without a header row
    141183,"false"
    2404499,"true"
    
  • tsv: Tab Seperated Values
    "count"	"is_null"
    141183	"false"
    2404499	"true"
    
  • tsv_headerless: TSV without header row
  • with_sql_values: SQL VALUES with the header columns, suitable to copy/paste into a WITH statement for later usage
    ("count", "is_null") AS (VALUES (141183, false), (2404499, true))
    
    This can be used later like:
    WITH original_values ("count", "is_null") AS (VALUES (141183, false), (2404499, true)),
    select * from data join original_values ...