Deliver OpenStreetMap data in GeoJSON and MVT tile formats
Project description
DjangoStreetMap
DjangoStreetMap is a Django application to load OSM data into a PostGIS database and deliver OSM data as MVT tiles.
Stack
- Python 3.11+
- Django 5.2 LTS
- Pydantic 2
- PostGIS 3.4+ (Postgres 16 recommended)
- Package managed with uv
Docs
docs/architecture.md— tile pipeline, MvtQuery variants, SRID choices, cache protocol, how to write a new tile view.docs/api.md— cheatsheet of every public symbol.examples/minimal/— runnable standalone project:make db-up install migrate import runserver→ tiles at:8000/tiles/....
OpenStreetMap Vector Tiles
"A vector tile is a lightweight data format for storing geospatial vector data"
For an introduction to MVT (Mapbox Vector Tiles) see the mapbox docs. For an introduction to OSM see openstreetmap.org.
Purpose
- Import OSM data as Django models
- Expose Django models as MVT geographic format data
Tile generation is much faster when geometry is in srid=3857.
Prerequisites
You need the gdal libraries installed.
On Ubuntu:
sudo apt install binutils libproj-dev gdal-bin
Otherwise refer to the Django docs "Installing geospatial libraries".
Adding to a Project
uv add djangostreetmap
Extend INSTALLED_APPS:
INSTALLED_APPS = [
...,
"django.contrib.gis",
"djangostreetmap",
"osmflex",
]
(Recommended) Set your cache
You likely want a fast cache for tiles (e.g. Memcached). If not configured, the default cache is used.
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.PyMemcacheCache",
"LOCATION": "127.0.0.1:11211",
}
}
Development
Set up a PostGIS container
docker run --rm -d \
--name djsm_postgis \
-e POSTGRES_DB=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=post1234 \
-p 49155:5432 \
postgis/postgis:16-3.4 \
-c fsync=off -c shared_buffers=4096MB
Install dependencies
uv sync --dev
Run tests
uv run pytest
Lint / format / type-check
uv run ruff check .
uv run ruff format .
uv run mypy djangostreetmap maplibre
Pre-commit hooks
uv run pre-commit install
uv run pre-commit run --all-files
Releasing
Releases are automated via GitHub Actions (.github/workflows/release.yml) using
PyPI Trusted Publishing (OIDC). To cut a release:
- Bump
versioninpyproject.tomlonmain; commit and merge. - Tag the merged commit with the same version (no
vprefix):git tag 0.3.0 && git push origin 0.3.0
- The workflow verifies the tag matches
pyproject.toml, that the commit is onmain, builds sdist + wheel, publishes to PyPI, and creates a GitHub Release with auto-generated notes.
One-time PyPI setup (maintainer): on the PyPI project page, add a Trusted
Publisher for the catalpainternational/djangostreetmap repo, workflow
release.yml, environment pypi.
Writing Views
Subclass TileLayerView with MvtQuery layers:
class RoadLayerView(TileLayerView):
layers = [
MvtQuery(
table=OsmHighway._meta.db_table,
attributes=["name"],
filters=[f"\"highway\"='{road_class}'"],
layer=road_class,
)
for road_class in ("primary", "secondary", "tertiary")
]
Register the URL:
path("highways/<int:zoom>/<int:x>/<int:y>.pbf", RoadLayerView.as_view()),
Importing OSM Data
Fetch a .osm.pbf extract (e.g. from Geofabrik):
wget https://download.geofabrik.de/asia/east-timor-latest.osm.pbf
You need osm2pgsql >= 1.3. The osmflex app provides two management commands
to populate the models:
./manage.py run_osm2pgsql /path/to/east-timor-latest.osm.pbf
./manage.py import_from_pgosmflex
Exploring Data
- Django admin: http://localhost:8000/admin/osmflex
- psql:
psql --host localhost --username postgres --port 49155 - QGIS: add a Postgres connection to
localhost:49155, databasepostgres.
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 djangostreetmap-0.3.2.tar.gz.
File metadata
- Download URL: djangostreetmap-0.3.2.tar.gz
- Upload date:
- Size: 115.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a5c96f255292f9033fd9b83c69de48dfabab7d3d9b4aae78240c39ee3660351
|
|
| MD5 |
d8f20d24b2f8bf53117554b66b0d0792
|
|
| BLAKE2b-256 |
88e3e360528c31572c63561a448dfb515df903939e6d74c19b31cc96f5b9d084
|
Provenance
The following attestation bundles were made for djangostreetmap-0.3.2.tar.gz:
Publisher:
release.yml on catalpainternational/djangostreetmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangostreetmap-0.3.2.tar.gz -
Subject digest:
5a5c96f255292f9033fd9b83c69de48dfabab7d3d9b4aae78240c39ee3660351 - Sigstore transparency entry: 2098519168
- Sigstore integration time:
-
Permalink:
catalpainternational/djangostreetmap@26dd6fddc813358b8f346cddc32951d77b375968 -
Branch / Tag:
refs/tags/0.3.2 - Owner: https://github.com/catalpainternational
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@26dd6fddc813358b8f346cddc32951d77b375968 -
Trigger Event:
push
-
Statement type:
File details
Details for the file djangostreetmap-0.3.2-py3-none-any.whl.
File metadata
- Download URL: djangostreetmap-0.3.2-py3-none-any.whl
- Upload date:
- Size: 54.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a13feec64b7907600c01e4f3b9b87caaab3392b54472f8b8e48c0f1ec2c73f7d
|
|
| MD5 |
bd66f8c26011446eca9151cce3327594
|
|
| BLAKE2b-256 |
a2e70c498c119b076dc2fbb4fb1532f7eb754f0896867fe737c155266f567cb9
|
Provenance
The following attestation bundles were made for djangostreetmap-0.3.2-py3-none-any.whl:
Publisher:
release.yml on catalpainternational/djangostreetmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
djangostreetmap-0.3.2-py3-none-any.whl -
Subject digest:
a13feec64b7907600c01e4f3b9b87caaab3392b54472f8b8e48c0f1ec2c73f7d - Sigstore transparency entry: 2098519506
- Sigstore integration time:
-
Permalink:
catalpainternational/djangostreetmap@26dd6fddc813358b8f346cddc32951d77b375968 -
Branch / Tag:
refs/tags/0.3.2 - Owner: https://github.com/catalpainternational
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@26dd6fddc813358b8f346cddc32951d77b375968 -
Trigger Event:
push
-
Statement type: