Import OpenStreetMap data into Django using osm2pgsql (flex output)
Project description
osmflex
A Django app that mirrors pgosm-flex output, giving you an ORM-shaped view of OpenStreetMap data imported via osm2pgsql.
Stack
- Python 3.11+
- Django 5.2 LTS
- PostGIS 16-3.4+
- Package managed with uv
Install
uv add osmflex
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...,
"django.contrib.gis",
"osmflex",
]
Import OSM data
osmflex ships two management commands:
./manage.py run_osm2pgsql /path/to/foo.osm.pbf # writes schema osm.*
./manage.py import_from_pgosmflex --truncate # upserts into osmflex_*
Then query with the Django ORM:
>>> from osmflex.models import AmenityPoint
>>> AmenityPoint.objects.count()
14827
>>> AmenityPoint.objects.tagged()[:5] # annotates each row with the full OSM tag JSONB
End-to-end runnable example: examples/minimal_import/
walks through fetching a Geofabrik extract and running the full pipeline in a
disposable PostGIS container. Try:
cd examples/minimal_import
make db-up install migrate pbf import psql
Docs
docs/architecture.md— the pgosm-flex → Django pipeline, taxonomy, SRID choice, howupsert_sqlmangles source-table names, how to add your ownOsmsubclass.docs/api.md— cheatsheet of every public export.
Prerequisites
osm2pgsql≥ 1.6 — install via package manager (sudo apt install osm2pgsqlon modern Ubuntu;brew install osm2pgsqlon macOS) or build from source.- PostGIS — 3.4+ recommended.
- The bundled pgosm-flex LUA config in
osmflex/management/flex-config/is sourced from rustprooflabs/pgosm-flex.
Development
uv sync --dev
uv run pytest # 24 tests
uv run ruff check .
uv run mypy osmflex
Releasing
Releases are automated via .github/workflows/release.yml using PyPI Trusted
Publishing (OIDC). To cut a release:
- Bump
versioninpyproject.tomlonmain; merge. - Tag the merged commit with the same version (no
vprefix):git tag 0.3.1 && git push origin 0.3.1
- The workflow verifies tag/pyproject match, builds sdist + wheel, publishes to PyPI, and creates a GitHub Release with generated notes.
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 osmflex-0.3.1.tar.gz.
File metadata
- Download URL: osmflex-0.3.1.tar.gz
- Upload date:
- Size: 92.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f85d6ee8a8f34b1d3c33753a3b6cddba50671c44a739b360f6489676c11e4b6d
|
|
| MD5 |
f12fdc20b44eb8cf961be99253711a93
|
|
| BLAKE2b-256 |
6b646856b673fd28bc72d9b0f9e308fd82314b6091894bfcb67cb8f03c8ae0d1
|
Provenance
The following attestation bundles were made for osmflex-0.3.1.tar.gz:
Publisher:
release.yml on catalpainternational/osm2django
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osmflex-0.3.1.tar.gz -
Subject digest:
f85d6ee8a8f34b1d3c33753a3b6cddba50671c44a739b360f6489676c11e4b6d - Sigstore transparency entry: 2098371448
- Sigstore integration time:
-
Permalink:
catalpainternational/osm2django@427f291f956803f6ff23041142358a4f12e17535 -
Branch / Tag:
refs/tags/0.3.1 - Owner: https://github.com/catalpainternational
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@427f291f956803f6ff23041142358a4f12e17535 -
Trigger Event:
push
-
Statement type:
File details
Details for the file osmflex-0.3.1-py3-none-any.whl.
File metadata
- Download URL: osmflex-0.3.1-py3-none-any.whl
- Upload date:
- Size: 49.6 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 |
32eee5e996b412c07c61e0fe0f12ac9c1b6c8010751742ffe4e9b184dea5025d
|
|
| MD5 |
69601f94432865ef71b92aecae9a3001
|
|
| BLAKE2b-256 |
6f9c9328a221579c0c00d98667d12af08c5357c16a03ff148740c8d40e887c5e
|
Provenance
The following attestation bundles were made for osmflex-0.3.1-py3-none-any.whl:
Publisher:
release.yml on catalpainternational/osm2django
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osmflex-0.3.1-py3-none-any.whl -
Subject digest:
32eee5e996b412c07c61e0fe0f12ac9c1b6c8010751742ffe4e9b184dea5025d - Sigstore transparency entry: 2098371879
- Sigstore integration time:
-
Permalink:
catalpainternational/osm2django@427f291f956803f6ff23041142358a4f12e17535 -
Branch / Tag:
refs/tags/0.3.1 - Owner: https://github.com/catalpainternational
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@427f291f956803f6ff23041142358a4f12e17535 -
Trigger Event:
push
-
Statement type: