Async client for the Overpass API
Project description
A client for the Overpass API, a read-only API that serves up custom selected parts of OpenStreetMap data.
The Overpass API is optimized for data consumers that need a few elements within a glimpse or up to roughly 10 million elements in some minutes, both selected by search criteria like location, type of objects, tag properties, proximity, or combinations of them. To make use of it, you should familiarize yourself with Overpass QL, the query language used to select the elements that you want.
Contents
See also
- An overview of modules, classes and functions can be found in the API reference
- The version history is available in RELEASES.md
- There are some notebooks to check out in examples/
- Developers can find some instructions in CONTRIBUTING.md
- The Overpass API repository, its blog, its user's manual and its release notes
- Overpass Turbo to prototype your queries in your browser
Features
- Asynchronous requests using aiohttp
- Parallel queries within rate limits
- Fault tolerance through a (customizable) retry strategy
- Extras
Design Goals
- A small and stable set of core functionality.
- Good defaults for queries and retrying.
- Sensible and spec-compliant GeoJSON exports for all objects that represent spatial features.
- Detailed documentation that supplements learning about OSM and the Overpass API.
- Room for extensions that simplify querying and/or processing of spatial data in specific problem domains.
Usage
There are three basic steps to fetch the spatial data you need:
-
Formulate a query
- Either write your own custom query, f.e.
Query("node(5369192667); out;"), - or use one of the
Querysubclasses, f.e.SingleRouteQuery(relation_id=1643324).
- Either write your own custom query, f.e.
-
Call the Overpass API
- Prepare your client with
client = Client(user_agent=...). - Use
await client.run_query(query)to fetch the result set.
- Prepare your client with
-
Collect results
- Either access the raw result dictionaries with
query.result_set, - or use a collector, f.e.
collect_elements(query)to get a list of typedElements. - Collectors are often specific to queries -
collect_routesrequires aRouteQuery, for instance.
- Either access the raw result dictionaries with
Example: looking up a building in Hamburg
a) Results as Dictionaries
You may use the .result_set property to get a list of all query results
without any extra processing:
from aio_overpass import Client, Query
query = Query('way["addr:housename"=Elbphilharmonie]; out geom;')
client = Client()
await client.run_query(query)
query.result_set
[
{
"type": "way",
"id": 24981342,
# ...
"tags": {
"addr:city": "Hamburg",
"addr:country": "DE",
"addr:housename": "Elbphilharmonie",
# ...
},
}
]
b) Results as Objects
This will give you a user-friendly Python interface
for nodes,
ways,
and relations.
Here we use the .tags property:
from aio_overpass.element import collect_elements
elems = collect_elements(query)
elems[0].tags
{
"addr:city": "Hamburg",
"addr:country": "DE",
"addr:housename": "Elbphilharmonie",
# ...
}
c) Results as GeoJSON
The processed elements can also easily be converted to GeoJSON:
import json
json.dumps(elems[0].geojson, indent=4)
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
9.9832434,
53.5415472
],
...
]
]
},
"properties": {
"id": 24981342,
"type": "way",
"tags": {
"addr:city": "Hamburg",
"addr:country": "DE",
"addr:housename": "Elbphilharmonie",
...
},
...
},
"bbox": [
9.9832434,
53.540877,
9.9849674
53.5416212,
]
}
Choosing Extras
This library can be installed with a number of optional extras.
-
Install no extras, if you're fine with
dictresult sets. -
Install the
shapelyextra, if you would like the convenience of typed OSM elements. It is also useful if you are interested in elements' geometries, and either already use Shapely, or want a simple way to export GeoJSON.- This includes the
ptmodule to make it easier to interact with public transportation routes. Something seemingly trivial like listing the stops of a route can have unexpected pitfalls, since stops can have multiple route members, and may have a range of different tags and roles. This submodule will clean up the relation data for you.
- This includes the
-
Install the
networkxextra to enable thept_orderedmodule, if you want a route's path as a simple line from A to B. It is hard to do this consistently, mainly because ways are not always ordered, and stop positions might be missing. You can benefit from this submodule if you wish to- render a route's path between any two stops
- measure the route's travelled distance between any two stops
- validate the order of ways in the relation
- check if the route relation has gaps
-
Install the
joblibextra to speed uppt_ordered.collect_ordered_routes(), which can benefit greatly from parallelization.
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 aio_overpass-0.15.1.tar.gz.
File metadata
- Download URL: aio_overpass-0.15.1.tar.gz
- Upload date:
- Size: 50.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835ca2c0b7d00b011c657e30b2bad6e8a85d7e840740ef6f6e9009e57f9c5220
|
|
| MD5 |
d22a737b4614fe244132120c4f0bd8a4
|
|
| BLAKE2b-256 |
0feae343f7f314e47bad8bea890951da65fc41eb8ac15f95baa398d3881d15bc
|
Provenance
The following attestation bundles were made for aio_overpass-0.15.1.tar.gz:
Publisher:
publish.yml on timwie/aio-overpass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aio_overpass-0.15.1.tar.gz -
Subject digest:
835ca2c0b7d00b011c657e30b2bad6e8a85d7e840740ef6f6e9009e57f9c5220 - Sigstore transparency entry: 320577885
- Sigstore integration time:
-
Permalink:
timwie/aio-overpass@33cd875a8c84158b3e694b1937d569d0bf047d4e -
Branch / Tag:
refs/tags/v0.15.1 - Owner: https://github.com/timwie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@33cd875a8c84158b3e694b1937d569d0bf047d4e -
Trigger Event:
push
-
Statement type:
File details
Details for the file aio_overpass-0.15.1-py3-none-any.whl.
File metadata
- Download URL: aio_overpass-0.15.1-py3-none-any.whl
- Upload date:
- Size: 56.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3149887ef629251a378e0c9ca113c09b27a82acee2c67ca9cf86ba1e92142c53
|
|
| MD5 |
1c9e049edbfa2b2bff52576757321537
|
|
| BLAKE2b-256 |
2e134443797a1e2578d06c040c856b370cb542837aa274daac36535eccc351d3
|
Provenance
The following attestation bundles were made for aio_overpass-0.15.1-py3-none-any.whl:
Publisher:
publish.yml on timwie/aio-overpass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aio_overpass-0.15.1-py3-none-any.whl -
Subject digest:
3149887ef629251a378e0c9ca113c09b27a82acee2c67ca9cf86ba1e92142c53 - Sigstore transparency entry: 320577937
- Sigstore integration time:
-
Permalink:
timwie/aio-overpass@33cd875a8c84158b3e694b1937d569d0bf047d4e -
Branch / Tag:
refs/tags/v0.15.1 - Owner: https://github.com/timwie
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@33cd875a8c84158b3e694b1937d569d0bf047d4e -
Trigger Event:
push
-
Statement type: