Reference
dataeuropa: access the data.europa.eu open data portal (Search API, Registry, SPARQL).
search_datasets(q=None, *, lang='en', as_dataframe=True, **kw)
Search datasets and return a table (pandas DataFrame if available, else list of dicts).
Accepts all keyword arguments of :func:search. count (total hits) is stored in
df.attrs["count"] for DataFrames.
search(q=None, *, filters='dataset', facets=None, limit=10, page=0, sort=None, country=None, catalog=None, format=None, license=None, category=None, publisher=None, keywords=None, hvd=None, min_date=None, max_date=None, date_type=None, bbox=None, aggregation=False, extra=None)
Raw Search API call. Returns the result object: count, results, facets...
country takes ISO-2 codes ("pt"); format takes ids such as "CSV";
category takes DCAT-AP theme codes ("ENVI"). Use :func:facet_values to discover ids.
sort is e.g. "modified+desc".
bbox is (min_lon, min_lat, max_lon, max_lat) in WGS84 degrees. A dataset matches when
its spatial extent overlaps the box, so datasets covering all of Europe or the world match any
box. Datasets without a spatial extent (about half the portal) never match.
With limit=0 the result can come from the response cache (see :func:cache_on).
fetch_datasets(q=None, *, max_results=1000, lang='en', as_dataframe=True, **kw)
Collect up to max_results datasets (via scroll) into a table.
iter_datasets(q=None, *, max_results=None, page_size=500, **kw)
Yield raw dataset records for an arbitrarily large result set using scroll.
get_dataset(dataset_id, *, raw=False, lang='en')
Full metadata record for one dataset (id as shown in search results).
distributions(dataset_id, *, lang='en', files_only=False, as_dataframe=True)
Distributions (files, services, pages) of a dataset as a table, one row each.
The kind column says what each one is: "file", "service" (WMS, WFS, APIs, feeds),
"page" (a web page), "none" (no usable URL, e.g. a localhost placeholder) or
"unknown". files_only=True keeps only files.
download(url_or_row, dest, *, chunk=1 << 20, verify=True, resume=True, max_bytes=None)
Download a distribution to dest (a file path, or an existing directory to save it in under
its own name). Returns the local path. dest is required: nothing is written to the working
directory unless you pass it (e.g. ".").
Accepts a URL, or a row/dict from :func:distributions (uses its url). Streams to disk.
If the row has a checksum (checksum and checksum_algorithm; MD5, SHA-1 or SHA-256), the
file is checked against it. On a mismatch the file is deleted and ValueError is raised;
verify=False skips the check. byte_size is not checked: on the portal it is often a
placeholder (0, 1, 1024).
The file is written as <file>.part and renamed when complete. If a download is interrupted,
calling download again for the same URL and destination continues where it stopped, when
the server supports ranges and identifies the file (ETag or Last-Modified); a file that changed
meanwhile is downloaded again from the start. resume=False always starts from the start.
max_bytes stops a download that is (or is announced as) larger, deletes the partial file
and raises ValueError. Default: no limit.
load_distribution(url_or_row, *, format=None, sheet=None)
Download a distribution and read it into a pandas DataFrame.
Accepts a URL, or a row/dict from :func:distributions. Reads CSV and JSON (needs pandas),
XLSX (needs openpyxl) and Parquet (needs pyarrow). The format comes from format if given
("csv", "json", "xlsx", "parquet"), else from the row's format id, its media
type, then the URL's file extension. sheet picks an XLSX sheet by name or 0-based index
(default: the first).
CSV: the delimiter (, ; tab |) is taken from the header line, text is read as
UTF-8 with a Latin-1 fallback, and only empty cells count as missing. JSON: an array of
objects, or an object holding exactly one such array; keys become columns.
Raises ValueError for services (WMS, WFS, APIs), compressed archives, HTML pages served
instead of data, formats it cannot tell or read, and files that fail their checksum (see
:func:download).
load_geodata(url_or_row, *, layer=None, crs=None, max_mb=200, max_features=10000)
Download a geodata distribution, or read a feature service, into a geopandas GeoDataFrame.
Accepts a URL, or a row/dict from :func:distributions. Needs geopandas and pyogrio
(pip install 'dataeuropa[geo]'); GDAL does the reading, so any vector format it knows
works: GeoJSON, Shapefile, GeoPackage, KML/KMZ, GML, GPX, MapInfo TAB, FlatGeobuf, file
geodatabase.
ZIP archives (how shapefiles are published) are opened in place. Inside, the one geodata file
is read (a .shp with its .dbf/.shx/.prj, .gpkg, .geojson, .kml, .gml, .gpx, .tab, .fgb, or a
.gdb folder); if there are several, layer picks one by file name (without extension),
otherwise ValueError lists them. Archives inside archives are not opened.
layer picks a layer by name or 0-based position in files with several (GeoPackage, file
geodatabase); by default the first is read, with a warning if there are more.
The source coordinate reference system is kept. crs (e.g. "EPSG:4326") reprojects; a
file without one (a shapefile without .prj) is read as stored, with a warning.
Files over max_mb megabytes (default 200) are not downloaded; max_mb=None lifts the
limit.
Feature services are read too: WFS (service=WFS URLs, WFS format ids) and OGC API
Features (collection or landing-page URLs, OGCFEAT format ids). GDAL pages through the
results. Each collection or feature type is a layer. At most max_features features
(default 10,000) are read, with a warning when there are more; max_features=None reads all.
Raises ValueError for other services (WMS, ...), web pages, HTML served instead of data,
files or services GDAL cannot read, and checksum mismatches.
cache_on(dir=None, ttl=None)
Turn on the on-disk response cache for this session. Returns the cache folder.
Cached: dataset records (:func:get_dataset, :func:distributions), the catalogue list
(:func:catalogues), and searches with limit=0 (:func:facet_values, :func:count).
Other searches, SPARQL and file downloads are never cached.
dir defaults to DATAEUROPA_CACHE_DIR, else the operating system's cache folder.
ttl is how long a response stays valid, in seconds; it defaults to
DATAEUROPA_CACHE_TTL, else one day. The cache is off unless this is called or
DATAEUROPA_CACHE=1 is set.
cache_off()
Turn off the response cache for this session (cached files stay; see :func:clear_cache).
clear_cache()
Delete all cached responses. Returns how many were deleted.
facet_values(facet, q=None, *, top=50, filters='dataset', **kw)
List the values (and counts) of a facet, e.g. "country", "format", "categories".
count(q=None, **kw)
Number of hits for a query (no records transferred).
catalogues()
Ids of all harvested catalogues.
get_rdf(dataset_id, fmt='ttl')
Dataset metadata as RDF text. fmt: ttl (Turtle) or jsonld.
sparql(query, *, as_dataframe=True)
Run a SPARQL SELECT/ASK query against data.europa.eu. Returns a table of plain values.
pick_lang(value, lang='en')
Collapse a {lang: text} mapping to one string (lang, then en, then any).
summarise_dataset(d, lang='en')
Flatten one dataset record to the fields people usually want.