Overpy - Overpass API Wrapper
raw JSON → 0.7 verified Fri May 01 auth: no python
Overpy is a Python wrapper for the OpenStreetMap Overpass API, allowing querying of OSM data with Overpass QL. Current version is 0.7, requiring Python >=3.6. Release cadence is low; the library is in maintenance mode.
pip install overpy Common errors
error overpy.exception.OverpassException: Error 429 Too Many Requests ↓
cause Request rate limited by Overpass server.
fix
Add delays between queries (e.g., time.sleep(10)) or use a more generous rate limit.
error TypeError: 'Node' object is not subscriptable ↓
cause Using index notation on a Node result instead of .tags dictionary.
fix
Access tags via node.tags['key'] or node.tags.get('key')
error AttributeError: 'NoneType' object has no attribute 'tags' ↓
cause Result element is None because the query returned no data.
fix
Check if result is None before accessing attributes, or handle in try/except.
Warnings
gotcha The Overpass API has rate limits and usage policies. Overpy does not handle retries; you must handle HTTP errors and API errors yourself. ↓
fix Wrap queries in try/except blocks and implement exponential backoff for retries.
gotcha The default user agent is old and may be blocked. Some Overpass instances (e.g., overpass-api.de) require a custom user agent. ↓
fix Set a custom user agent: Overpass(user_agent='YourApp/1.0')
deprecated The old 'Overpass(url="http://overpass-api.de/api/interpreter")' pattern without explicit user agent is discouraged. ↓
fix Use Overpass(user_agent='YourApp/1.0')
Imports
- Overpass
from overpy import Overpass - OverpassException
from overpy import OverpassException
Quickstart
import overpy
api = overpy.Overpass()
result = api.query("""
node(50.745,7.17,50.75,7.18)["amenity"="restaurant"];
out body;
""")
for node in result.nodes:
print(f"Node ID: {node.id}, Tags: {node.tags}")