we have with Overpass API python wrapper a thin Python wrapper around the OpenStreetMap Overpass API https://github.com/mvexel/overpass-api-python-wrapper
we have so
You can try this.
import overpass
api = overpass.API()
query = """
[out:csv(::id,::type,"name","addr:postcode","addr:city",
"addr:street","addr:housenumber","website"," contact:email=*")][timeout:30];
area[name="Madrid"]->.a;
( node(area.a)[amenity=hospital];
way(area.a)[amenity=hospital];
rel(area.a)[amenity=hospital];);
out;
"""
resp = api._get_from_overpass(query)
data = [row.split('\t') for row in resp.text.split('\n')]
Output:
for x in data[:5]:
print(x)
# ['@id', '@type', 'name', 'addr:postcode', 'addr:city', 'addr:street', 'addr:housenumber', 'website', ' contact:email=*']
# ['597375537', 'node', 'Centro de especialidades Emigrantes', '', '', '', '', '', '']
# ['1437313175', 'node', '', '', '', '', '', '', '']
# ['1595068136', 'node', '', '', '', '', '', '', '']
# ['2320596216', 'node', '', '', '', '', '', '', '']
Or
api = overpass.API()
query = """
area[name="Madrid"]->.a;
( node(area.a)[amenity=hospital];
way(area.a)[amenity=hospital];
rel(area.a)[amenity=hospital];);
"""
fmt = 'csv(::id,::type,"name","addr:postcode","addr:city","addr:street","addr:housenumber","website"," contact:email=*")'
data = api.get(query, responseformat=fmt)
Output:
for x in data[:5]:
print(x)
# ['@id', '@type', 'name', 'addr:postcode', 'addr:city', 'addr:street', 'addr:housenumber', 'website', ' contact:email=*']
# ['597375537', 'node', 'Centro de especialidades Emigrantes', '', '', '', '', '', '']
# ['1437313175', 'node', '', '', '', '', '', '', '']
# ['1595068136', 'node', '', '', '', '', '', '', '']
# ['2320596216', 'node', '', '', '', '', '', '', '']