1
0
Fork
You've already forked overpass-api-python-wrapper
0
Python interface for the OpenStreetMap Overpass API
  • Python 97.9%
  • Shell 2.1%
2026年05月04日 02:16:33 +02:00
.agents/logs test: cover unicode csv responses 2026年05月03日 18:05:09 -06:00
.forgejo/workflows chore: complete phase 7 validation cleanup 2026年05月02日 16:18:49 -06:00
.pi chore: expose pi agent context 2026年05月02日 14:43:37 -06:00
assets chore: add recording 2024年08月10日 15:55:40 -06:00
examples docs: complete phase 8 cleanup 2026年05月02日 16:24:35 -06:00
overpass fix: handle html overpass errors 2026年05月03日 11:27:56 -06:00
plans test: cover unicode csv responses 2026年05月03日 18:05:09 -06:00
scripts chore: validate python 3.10 through 3.14 2026年05月02日 16:11:28 -06:00
tests test: cover unicode csv responses 2026年05月03日 18:05:09 -06:00
.gitignore chore: add coverage reporting 2026年05月02日 16:01:20 -06:00
.tool-versions chore: replace tox workflow with uv 2026年05月02日 16:07:14 -06:00
AGENTS.md docs: plan issue 99 unicode csv verification 2026年05月03日 18:03:15 -06:00
CHANGELOG.md docs: include issue fixes in 0.8.1 changelog 2026年05月03日 11:31:24 -06:00
conftest.py chore: add ruff quality gate 2026年05月02日 15:48:14 -06:00
DESIGN-1.0.md docs: add user-facing 1.0 design document, fix README link 2026年05月02日 17:58:09 -06:00
DEVELOPMENT.md chore: complete phase 7 validation cleanup 2026年05月02日 16:18:49 -06:00
LICENSE.txt
MANIFEST.in docs: complete phase 8 cleanup 2026年05月02日 16:24:35 -06:00
pyproject.toml feat: add 0.8.1 deprecation warnings 2026年05月02日 18:28:26 -06:00
README.md doc: readme update 2026年05月03日 11:54:58 -06:00
README.rst docs: complete phase 8 cleanup 2026年05月02日 16:24:35 -06:00
RELEASE.md docs: complete phase 8 cleanup 2026年05月02日 16:24:35 -06:00
uv.lock feat: add 0.8.1 deprecation warnings 2026年05月02日 18:28:26 -06:00

Overpass API python wrapper

Overpass API for Python.

PyPI - Version

Install it

pip install overpass

Roadmap

0.8 is the final release in the 0.8 series. It will receive bug fixes and security updates only. No new features will be added to 0.8.

We are actively working toward 1.0, which will be a significant modernization: new OverpassClient API, structured result objects, a typed query builder, richer exceptions, and a migration from requests to httpx. See the 1.0 design document for the full picture.

We would love your input. If you use this library, please read the design doc and open an issue with feedback — what works for your use case, what doesn't, and what we may have missed.

Supported Python Versions

This project is tested and supported on Python 3.10 through 3.14.

Development

Use uv for local development:

uv sync --extra dev
scripts/check

DEVELOPMENT.md contains the full contributor command reference, including live API test instructions. RELEASE.md contains the release checklist.

Migrating to 1.0

The 0.8.x line is the compatibility and deprecation path for 1.0. Version 0.8.1 emits DeprecationWarning when code uses APIs that are removed or renamed in 1.0, including API, MapQuery, WayQuery, Utils.to_overpass_id, uppercase API.Get/API.Search, legacy exception names, and API.get() arguments that are replaced by the new query/result model.

Run your test suite with deprecation warnings enabled before moving to 1.0:

python -W default::DeprecationWarning -m pytest

See DESIGN-1.0.md for the planned 1.0 API and compatibility mapping. In particular, Utils.to_overpass_id(..., area=True) has no 1.0 replacement because Overpass API 0.7.57+ no longer supports legacy way-derived 2400xxx area IDs; query closed ways directly instead.

Usage

API() constructor

First, create an API object.

import overpass
api = overpass.API()

The API constructor takes several parameters, all optional:

endpoint

The default endpoint is https://overpass-api.de/api/interpreter but you can pass in another instance:

api = overpass.API(endpoint="https://overpass.myserver/interpreter")

timeout

The default timeout is 25 seconds, but you can set it to whatever you want.

api = overpass.API(timeout=600)

debug

Setting this to True will get you debug output.

Getting data from Overpass: get()

Most users will only ever need to use the get() method. There are some convenience query methods for common queries as well, see below.

response = api.get('node["name"="Salt Lake City"]')

response will be a dictionary representing the JSON output you would get from the Overpass API directly.

Note that the Overpass query passed to get() should not contain any out or other meta statements. See verbosity below for how to control the output.

Another example:

>>> [(feature["properties"]["name"], feature["id"]) for feature in response["features"]]
[("Salt Lake City", 150935219), ("Salt Lake City", 585370637)]

You can find more examples in the examples/ directory of this repository.

The get() method takes a few parameters, all optional having sensible defaults.

verbosity

You can set the verbosity of the Overpass query out directive using the same keywords Overpass does. In order of increased verbosity: ids, skel, body, tags, meta. As is the case with the Overpass API itself, body is the default.

>>> import overpass
>>> api = overpass.API()
>>> data = api.get('way(42.819,-73.881,42.820,-73.880);(._;>;)', verbosity='geom')
>>> [f for f in data.features if f.geometry['type'] == "LineString"]

(from a question on GIS Stackexchange)

responseformat

You can set the response type of your query using get()'s responseformat parameter to GeoJSON (geojson, the default), plain JSON (json), CSV (csv), and OSM XML (xml).

response = api.get('node["name"="Salt Lake City"]', responseformat="xml")

If you choose csv, you will need to specify which fields you want, as described here in the Overpass QL documentation. An example:

response = api.get('node["name"="Springfield"]["place"]', responseformat="csv(name,::lon,::lat)")

The response will be a list of lists:

[
 ['name', '@lon', '@lat'],
 ['Springfield', '-3.0645656', '56.2952787'],
 ['Springfield', '0.4937446', '51.7487585'],
 ['Springfield', '-2.4194716', '53.5732892'],
 ['Springfield', '25.5454526', '-33.9814866'],
 ....
]

build

We will construct a valid Overpass QL query from the parameters you set by default. This means you don't have to include 'meta' statements like [out:json], [timeout:60], [out body], etcetera. You just supply the meat of the query, the part that actually tells Overpass what to query for. If for whatever reason you want to override this and supply a full, valid Overpass QL query, you can set build to False to make the API not do any pre-processing.

date

You can query the data as it was on a given date. You can give either a standard ISO date alone (YYYY-MM-DD) or a full overpass date and time (YYYY-MM-DDTHH:MM:SSZ, i.e. 2020年04月28日T00:00:00Z). You can also directly pass a date or datetime object from the datetime library.

Pre-cooked Queries: MapQuery, WayQuery

In addition to just sending your query and parse the result, overpass provides shortcuts for often used map queries. To use them, just pass them like to normal query to the API.

MapQuery

This is a shorthand for a complete ways and relations query in a bounding box (the 'map call'). You just pass the bounding box to the constructor:

MapQuery = overpass.MapQuery(50.746,7.154,50.748,7.157)
response = api.get(MapQuery)

WayQuery

This is shorthand for getting a set of ways and their child nodes that satisfy certain criteria. Pass the criteria as a Overpass QL stub to the constructor:

way_query = overpass.WayQuery('["name"="Highway 51"]')
response = api.get(way_query)

Testing

Run the default hermetic test suite with:

uv run python -W default -m pytest

Run all required local validation, matching hosted Forgejo/Codeberg CI, with:

scripts/check

Live API coverage is opt-in only and is not part of required validation:

USE_LIVE_API=true uv run python -m pytest -m live_api

FAQ

I need help or have an idea for a feature

Create a new issue.

Where did the CLI tool go?

The command line tool was deprecated in version 0.4.0.

See also

There are other python modules that do similar things.