API reference

All public functions are available from the top-level package:

import pyerviss as pv

Querying

pyerviss.get_ili(countries=None, start=None, end=None, season=None, age_groups=None, as_of=None)

Weekly influenza-like illness (ILI) consultation rates (primary care).

Parameters:
  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive, e.g. “Italy” or [“FR”, “Spain”]. Default: all countries.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • age_groups (str | Iterable[str] | None) – Age group(s) among “0-4”, “5-14”, “15-64”, “65+” and “total”. Default: all. Before 2022-W25, some countries only have “total”.

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“ili”, “ari” or “sari”), country, country_code, year_week, date (Sunday of the week), age, value (the rate) and unit (e.g. “per 100,000 population”). Empty if nothing matches. With as_of, also vintage: the date of the ECDC snapshot a row comes from, or NaT for weeks older than the snapshot covers.

Raises:
  • InvalidParameterError – Unknown indicator, country or age group, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no data for this indicator.

Return type:

DataFrame

pyerviss.get_ari(countries=None, start=None, end=None, season=None, age_groups=None, as_of=None)

Weekly acute respiratory infection (ARI) consultation rates (primary care).

Parameters:
  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive, e.g. “Italy” or [“FR”, “Spain”]. Default: all countries.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • age_groups (str | Iterable[str] | None) – Age group(s) among “0-4”, “5-14”, “15-64”, “65+” and “total”. Default: all. Before 2022-W25, some countries only have “total”.

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“ili”, “ari” or “sari”), country, country_code, year_week, date (Sunday of the week), age, value (the rate) and unit (e.g. “per 100,000 population”). Empty if nothing matches. With as_of, also vintage: the date of the ECDC snapshot a row comes from, or NaT for weeks older than the snapshot covers.

Raises:
  • InvalidParameterError – Unknown indicator, country or age group, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no data for this indicator.

Return type:

DataFrame

pyerviss.get_sari(countries=None, start=None, end=None, season=None, age_groups=None, as_of=None)

Weekly severe acute respiratory infection (SARI) rates (hospitals; Slovakia: ICU).

Parameters:
  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive, e.g. “Italy” or [“FR”, “Spain”]. Default: all countries.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • age_groups (str | Iterable[str] | None) – Age group(s) among “0-4”, “5-14”, “15-64”, “65+” and “total”. Default: all. Before 2022-W25, some countries only have “total”.

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“ili”, “ari” or “sari”), country, country_code, year_week, date (Sunday of the week), age, value (the rate) and unit (e.g. “per 100,000 population”). Empty if nothing matches. With as_of, also vintage: the date of the ECDC snapshot a row comes from, or NaT for weeks older than the snapshot covers.

Raises:
  • InvalidParameterError – Unknown indicator, country or age group, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no data for this indicator.

Return type:

DataFrame

pyerviss.get_data(indicator, countries=None, start=None, end=None, season=None, age_groups=None, as_of=None)

Get rates for an indicator, optionally filtered.

Parameters:
  • indicator (str) – “ili”, “ari” or “sari”.

  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive, e.g. “Italy” or [“FR”, “Spain”]. Default: all countries.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • age_groups (str | Iterable[str] | None) – Age group(s) among “0-4”, “5-14”, “15-64”, “65+” and “total”. Default: all. Before 2022-W25, some countries only have “total”.

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“ili”, “ari” or “sari”), country, country_code, year_week, date (Sunday of the week), age, value (the rate) and unit (e.g. “per 100,000 population”). Empty if nothing matches. With as_of, also vintage: the date of the ECDC snapshot a row comes from, or NaT for weeks older than the snapshot covers.

Raises:
  • InvalidParameterError – Unknown indicator, country or age group, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no data for this indicator.

Return type:

DataFrame

Positivity

pyerviss.get_positivity(pathogen=None, setting=None, countries=None, start=None, end=None, season=None, as_of=None)

Weekly test positivity for influenza, RSV and SARS-CoV-2.

Positivity is the percentage of tested samples that were positive. Primary care samples come from patients with ILI and/or ARI at sentinel GPs; hospital samples from SARI patients. Data is available for all ages combined only.

Parameters:
  • pathogen (str | Iterable[str] | None) – “influenza”, “rsv” or “sars-cov-2” (case-insensitive; “flu” and “covid” are accepted), or a list. Default: all three.

  • setting (str | Iterable[str] | None) – “primary care” or “hospital”, or a list. Default: both.

  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive. “EU/EEA” (code “EU”) is ECDC’s aggregate for the region. Default: all countries.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“positivity”), setting, pathogen (“Influenza”, “RSV” or “SARS-CoV-2”), country, country_code, year_week, date (Sunday of the week), age (“total”), value (positivity in percent), unit (“%”), tests and detections (the counts positivity is computed from; small numbers of tests make positivity noisy). Empty if nothing matches. With as_of, also vintage: the date of the ECDC snapshot a row comes from, or NaT for weeks older than the snapshot covers.

Raises:
  • InvalidParameterError – Unknown pathogen, setting or country, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no positivity data for the requested pathogens and settings.

Return type:

DataFrame

pyerviss.get_detections(pathogen=None, setting=None, countries=None, start=None, end=None, season=None, level='type', as_of=None)

Weekly influenza and RSV detections by type or subtype, with their shares.

For each country and week: how many positive samples were of each type (influenza A, B; RSV-A, RSV-B) or subtype (A(H1)pdm09, A(H3), B/Victoria…), and that category’s share of all detections of the pathogen. Samples that were not typed or subtyped are kept as categories (“untyped”, “A (unknown)”, “B (unknown)”), so shares add up to 1; for shares among typed samples only, drop those rows and rescale.

ECDC only publishes categories with at least one detection: a category missing from a week means 0 detections. Weeks without any typed detection have no rows, and neither do weeks before a country started reporting types (for RSV, mostly before 2021).

Parameters:
  • pathogen (str | Iterable[str] | None) – “influenza” or “rsv” (case-insensitive; “flu” is accepted), or both. Default: both. SARS-CoV-2 detections are not split by type.

  • setting (str | Iterable[str] | None) – “primary care” or “hospital”, or a list. Default: both.

  • countries (str | Iterable[str] | None) – Country name(s) or ISO2 code(s), case-insensitive. Default: all.

  • start (str | date | None) – First week to include, as “2024-W40”, “2024-10-01” or a date.

  • end (str | date | None) – Last week to include (inclusive), in the same formats.

  • season (str | Iterable[str] | None) – Season(s) such as “2024/25”, which runs from 2024-W40 to 2025-W39. Cannot be combined with start/end.

  • level (str) – “type” (influenza A, B, untyped; RSV-A, RSV-B, untyped) or “subtype” (A(H1)pdm09, A(H3), A (unknown), B/Victoria, B/Yamagata, B (unknown), untyped; RSV is the same as at type level).

  • as_of (str | date | None) – Return the data as ECDC published it on this date (a date or “YYYY-MM-DD”), for backtesting without later revisions. Default: current data.

Returns:

DataFrame with columns indicator (“detections”), setting, pathogen (“Influenza” or “RSV”), type, subtype (with level=”subtype” only), country, country_code, year_week, date (Sunday of the week), age (“total”), value (number of detections), unit (“count”), share (value / total, NaN when total is 0) and total (detections of the pathogen that week, summed over the categories). With as_of, also vintage. Empty if nothing matches.

Raises:
  • InvalidParameterError – Unknown or untyped pathogen (SARS-CoV-2), unknown setting, country or level, a malformed week or season, or season combined with start/end.

  • DataNotFoundError – A requested country has no detections for the requested pathogens and settings.

Return type:

DataFrame

Past vintages

Pass as_of to any query function above to get data as ECDC published it on a past date; see Past vintages (backtesting).

pyerviss.list_vintages(indicator, setting=None)

Dates of ECDC’s snapshots of an indicator, usable as as_of, oldest first.

Parameters:
  • indicator (str) – “ili”, “ari”, “sari” or “positivity”.

  • setting (str | Iterable[str] | None) – For positivity, “primary care” or “hospital”, or a list. Default: both (dates on which either was published).

Return type:

list[date]

ILI and ARI snapshots start on 2023-11-24, primary care positivity on 2023-12-01, SARI and hospital positivity on 2024-11-08. Most weeks have one snapshot, but ECDC skipped some weeks.

Plotting

Requires matplotlib: pip install "pyerviss[plot]".

pyerviss.plot_seasons(df: DataFrame, highlight: str | Iterable[str] | None = None, facet: None = None, sharey: bool = False, ax: matplotlib.axes.Axes | None = None, start_week: int = 25, past_seasons: int | None = 3) → matplotlib.axes.Axes
pyerviss.plot_seasons(df: DataFrame, highlight: str | Iterable[str] | None = None, *, facet: str, sharey: bool = False, ax: matplotlib.axes.Axes | None = None, start_week: int = 25, past_seasons: int | None = 3) → matplotlib.figure.Figure
pyerviss.plot_seasons(df: DataFrame, highlight: str | Iterable[str] | None, facet: str, sharey: bool = False, ax: matplotlib.axes.Axes | None = None, start_week: int = 25, past_seasons: int | None = 3) → matplotlib.figure.Figure

Plot one line per season, aligned on the week of the season (W25 to W24).

As on ERVISS’s dashboard, plotted seasons run from week 25 to week 24 of the next year, so the summer trough comes first and the autumn rise and winter peak are fully visible. A plotted season “2024/25” therefore runs from 2024-W25 to 2025-W24, unlike the season filter of queries (W40 to W39); pass start_week=40 to plot those.

Highlighted seasons are drawn in colour. For context, the 3 most recent other seasons are drawn in shades of grey (darker = more recent) and named in the legend. If df has ci_low and ci_high columns (see add_positivity_ci), the interval is drawn as a band around highlighted seasons. Weeks without data are left as gaps.

Parameters:
  • df (pandas.DataFrame) – A result of get_ili, get_ari, get_sari or get_positivity. Without facet it must contain a single series: one indicator, country and age group (and, for positivity, one pathogen and setting).

  • highlight (str | Iterable[str] | None) – Season(s) to draw in colour, e.g. “2024/25” or [“2023/24”, “2024/25”] (at most three). Default: the most recent season in df.

  • facet (str | None) – “country” or “age” to draw one panel per country or age group. Every other column must then have a single value.

  • sharey (bool) – Use the same y-axis range in all panels (facets only). Only allowed when all panels have the same unit.

  • ax (matplotlib.axes.Axes | None) – Matplotlib axes to draw on (without facet only). Default: a new figure.

  • start_week (int) – ISO week that starts a plotted season. Default 25.

  • past_seasons (int | None) – How many other seasons to draw for context, the most recent ones first. Default 3. None draws every season in the data, in a single grey labelled “other seasons”; 0 draws only the highlighted seasons.

Returns:

The matplotlib Axes without facet, or the Figure with facets.

Raises:
  • InvalidParameterError – df is empty or has several series, an invalid highlight, facet or sharey, or ax combined with facet.

  • ImportError – matplotlib is not installed.

Return type:

matplotlib.axes.Axes | matplotlib.figure.Figure

Derived columns

pyerviss.add_season_week(df, start_week=40)

Add the season and the week of the season to each row.

A season “2024/25” runs from 2024-W40 to 2025-W39. Its weeks are numbered from 1 (W40) to 52, or 53 in seasons containing an ISO week 53.

Parameters:
  • df (DataFrame) – A query result, or any DataFrame with a year_week column.

  • start_week (int) – ISO week that starts a season. Default 40, as in the season filter of queries; ERVISS’s dashboard uses 25 (a season “2024/25” then runs from 2024-W25 to 2025-W24).

Returns:

A copy of df with season (e.g. “2024/25”) and season_week (int) columns added.

Return type:

DataFrame

pyerviss.add_positivity_ci(df, level=0.95)

Add a confidence interval for positivity, computed from tests and detections.

Uses the Wilson score interval, which stays sensible for small numbers of tests (1 positive out of 1 test gives roughly 21% to 100%, not a confident 100%).

Parameters:
  • df (DataFrame) – A result of get_positivity, or any DataFrame with tests and detections columns.

  • level (float) – Confidence level, between 0 and 1. Default 0.95.

Returns:

A copy of df with ci_low and ci_high columns, in percent. They are missing (NaN) where tests are missing or zero.

Return type:

DataFrame

Discovering data

pyerviss.coverage(indicator, as_of=None)

Per country: first and last week with data, number of weeks, and unit.

Parameters:
  • indicator (str) – “ili”, “ari”, “sari” or “positivity”.

  • as_of (str | date | None) – Describe the data as ECDC published it on this date. Default: current data.

Returns:

A DataFrame. For rates, one row per country with columns country, country_code, first_week, last_week, n_weeks (weeks with data in any age group), age_groups and unit. For positivity, one row per setting, pathogen and country with columns setting, pathogen, country, country_code, first_week, last_week, n_weeks and unit.

Return type:

DataFrame

pyerviss.list_countries(indicator)

Countries with data for an indicator (“ili”, “ari”, “sari” or “positivity”).

Parameters:

indicator (str)

Return type:

list[str]

pyerviss.list_seasons(indicator=None)

Seasons with data, e.g. [“2014/15”, …, “2026/27”]. Default: any indicator.

Parameters:

indicator (str | None)

Return type:

list[str]

pyerviss.latest_week(indicator=None, as_of=None)

Most recent week with data, e.g. “2026-W38”. Default: across all indicators.

With as_of, the most recent week ECDC had published on that date.

Parameters:
  • indicator (str | None)

  • as_of (str | date | None)

Return type:

str

Cache

pyerviss.update_data()

Check all data files for updates now and download any that changed.

Return type:

None

pyerviss.clear_cache()

Delete all cached data files.

Return type:

None

Exceptions

All exceptions derive from PyERVISSError.

Custom exceptions for PyERVISS.

exception pyerviss.exceptions.PyERVISSError

Bases: Exception

Base exception for PyERVISS.

exception pyerviss.exceptions.DataNotFoundError

Bases: PyERVISSError

Raised when requested data is not available.

exception pyerviss.exceptions.DataFetchError

Bases: PyERVISSError

Raised when data fetching from remote source fails.

exception pyerviss.exceptions.InvalidParameterError

Bases: PyERVISSError

Raised when invalid parameters are provided.

exception pyerviss.exceptions.CacheError

Bases: PyERVISSError

Raised when cache operations fail.

Lower level

These are not needed for normal use.

pyerviss.data_loader.get_metadata(force_refresh=False)

Return data/metadata.json: last update, record counts, date ranges and units.

Parameters:

force_refresh (bool)

Return type:

dict[str, Any]

pyerviss.data_loader.load_csv(file_name, force_refresh=False)

Load a data file as a DataFrame with ECDC’s columns (value as float).

Parameters:
  • file_name (str)

  • force_refresh (bool)

Return type:

DataFrame

pyerviss.data_loader.fetch_file(file_name, force_refresh=False)

Return the path of an up-to-date cached copy of a data file.

Parameters:
  • file_name (str) – File name in the repository’s data/ folder, e.g. “ILIARIRates.csv”.

  • force_refresh (bool) – Check for updates now instead of waiting for the check interval.

Raises:

DataFetchError – The file could not be downloaded and no cached copy exists.

Return type:

Path

pyerviss.cache.get_cache_dir()

Return the cache directory, creating it if needed.

Return type:

Path

Weeks and seasons

ISO week and season helpers.

Weeks are ISO 8601 weeks written “YYYY-Www” (e.g. “2024-W40”). The date of a week is its last day, Sunday, matching RespiCast’s truth_date. A season “2024/25” runs from 2024-W40 to 2025-W39.

pyerviss.utils.parse_yearweek(year_week)

Split “2024-W40” into (2024, 40), checking that the week exists.

Parameters:

year_week (str)

Return type:

tuple[int, int]

pyerviss.utils.yearweek_to_date(year_week)

Last day (Sunday) of an ISO week: “2024-W40” -> date(2024, 10, 6).

Parameters:

year_week (str)

Return type:

date

pyerviss.utils.date_to_yearweek(d)

ISO week containing a date: date(2024, 10, 1) -> “2024-W40”.

Parameters:

d (date)

Return type:

str

pyerviss.utils.to_yearweek(value)

Normalize a week given as “2024-W40”, “2024-10-01”, a date or a datetime.

Parameters:

value (str | date)

Return type:

str

pyerviss.utils.parse_season(season)

First and last week of a season: “2024/25” -> (“2024-W40”, “2025-W39”).

Parameters:

season (str)

Return type:

tuple[str, str]

pyerviss.utils.check_start_week(start_week)

Raise InvalidParameterError unless start_week is an ISO week from 1 to 52.

Parameters:

start_week (int)

Return type:

None

pyerviss.utils.season_of(year_week, start_week=40)

Season a week belongs to: “2024-W40” -> “2024/25”, “2025-W39” -> “2024/25”.

With another start_week, seasons run from that week to the week before it, e.g. start_week=25: “2024-W25” -> “2024/25”, “2025-W24” -> “2024/25”.

Parameters:
  • year_week (str)

  • start_week (int)

Return type:

str