The answer from scai is partially correct,thank you! However not complete as you need to take some more steps. For example I had to use the request library to actually query the data as I couldn't download the data from overpass turbo as osm-xml (too big, I guess)
So my python code to get the data and store as geojson is:
import requests
import json
import codecs
import osm2geojson
overpass_url = "http://overpass-api.de/api/interpreter"
# Here the query from overpass-turbo
overpass_query = """
[out:json][timeout:25];
area[name="Deutschland"];
(
relation
["boundary"="administrative"]
["admin_level"="6"](area);
);
out body;
>;
out skel qt;
"""
response = requests.get(overpass_url,
params={'data': overpass_query})
data = response.json()
# Dump the data as json
with open(r'path/to/file.json', 'w') as f:
json.dump(data, f)
# Reread the json file and convert it to geojson with the osm2geo library
with codecs.open(r'path/to/file.json', 'r', encoding='utf-8') as data:
json = data.read()
# restructure to geojson
geojson = osm2geojson.json2geojson(json)
# Store restructured json as json to your local disk
with open(r'path/to/geofile.json', 'w') as f:
json.dump(geojson, f)
This stored json-file is then readable in e.g. QGIS and can then (if needed) exported as shapefile or so from QGIS.
I'm pretty sure that there is no need to first store it as json and then read it and then store it as geojson, but will try this out later.