Getting started¶
The ilostat Python package provides convenient access to
international labour statistics published by the International
Labour Organization (ILO).
This guide introduces the main functions for discovering, retrieving and working with ILOSTAT data.
Installation¶
The package is available on PyPI and requires Python 3.10 or later.
Install the package:
python -m pip install ilostat
To upgrade an existing installation:
python -m pip install --upgrade ilostat
Import the package:
import ilostat
Choose your data access interface¶
The package provides two complementary interfaces.
| Interface | Function | Purpose |
|---|---|---|
| Bulk data | get_df() |
Retrieve ILOSTAT datasets using native ILOSTAT conventions |
| SDMX | get_sdmx() |
Retrieve data and structural metadata using SDMX conventions |
Both interfaces integrate with pandas and support local caching.
Which interface should I use?
Use get_df() for general statistical analysis in Python.
Use get_sdmx() when working with SDMX-compatible
applications, component identifiers or structural metadata.
Discover available datasets¶
Retrieve the ILOSTAT table of contents:
toc = ilostat.get_toc()
print(toc.head())
The table of contents provides information about available datasets and their identifiers.
By default, the indicator data segment is used.
To retrieve the catalogue in French:
toc_fr = ilostat.get_toc(lang="fr")
Retrieve your first dataset¶
Use get_df() with an ILOSTAT dataset identifier:
df = ilostat.get_df("UNE_TUNE_SEX_AGE_NB_A")
print(df.head())
The result is a pandas DataFrame, ready for statistical analysis, visualization or export.
Filter observations¶
Restrict observations using the filters argument.
=== "Single country"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
filters={
"ref_area": "FRA",
},
)
```
=== "Multiple countries"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
filters={
"ref_area": ["FRA", "CHE"],
},
)
```
=== "Country, sex and time"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
filters={
"ref_area": ["FRA", "CHE"],
"sex": "SEX_F",
"timefrom": 2020,
"timeto": 2025,
},
)
```
Filters can combine multiple dimensions and time restrictions.
For more advanced filtering options, see Data access.
Work with codes and labels¶
By default, ILOSTAT data are returned using coded dimensions.
The type argument controls how these dimensions are represented.
=== "Codes"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
type="code",
)
```
=== "Labels"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
type="label",
)
```
=== "Codes and labels"
```python
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
type="both",
)
```
Labels are available in three languages:
| Language | Code |
|---|---|
| English | en |
| French | fr |
| Spanish | es |
For example, to retrieve French labels:
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
type="both",
lang="fr",
)
Retrieve multiple datasets¶
The get_df() function accepts either a single dataset
identifier or a collection of dataset identifiers.
dataset_ids = [
"UNE_TUNE_SEX_AGE_NB_A",
"UNE_DEAP_SEX_AGE_RT_A",
]
df = ilostat.get_df(dataset_ids)
Dataset identifiers can be discovered using get_toc().
Explore dictionaries and metadata¶
ILOSTAT provides dictionaries describing the codes used in its datasets.
Dictionaries¶
countries = ilostat.get_dic("ref_area")
sex = ilostat.get_dic("sex")
print(countries.head())
print(sex.head())
Dictionaries support the same three languages.
Dataset metadata¶
metadata = ilostat.get_metadata(
"UNE_TUNE_SEX_AGE_NB_A",
)
Dataset-specific dictionaries¶
dictionary = ilostat.get_dataset_dic(
"UNE_TUNE_SEX_AGE_NB_A",
)
Access data using SDMX¶
The get_sdmx() function uses SDMX component identifiers.
=== "Data"
```python
df = ilostat.get_sdmx(
"UNE_TUNE_SEX_AGE_NB_A",
filters={
"REF_AREA": "FRA",
"SEX": "SEX_F",
},
)
print(df.head())
```
=== "Structure"
```python
structure = ilostat.get_sdmx(
"UNE_TUNE_SEX_AGE_NB_A",
resource="structure",
)
print(structure)
```
=== "Codelist"
```python
codelist = ilostat.get_sdmx(
"UNE_TUNE_SEX_AGE_NB_A",
resource="codelist",
component="SEX",
)
print(codelist)
```
=== "Dataflows"
```python
dataflows = ilostat.get_sdmx(
resource="dataflow",
)
print(dataflows)
```
The SDMX interface is described in detail in the SDMX documentation.
Local caching¶
Downloaded resources are cached locally to improve performance and reduce repeated downloads.
Display the cache location:
print(ilostat.get_cache_dir())
Force a resource refresh:
df = ilostat.get_df(
"UNE_TUNE_SEX_AGE_NB_A",
refresh=True,
)
For additional cache management options, see Cache management.
Export your results¶
Since data are returned as pandas DataFrames, you can use standard pandas methods to export your results.
=== "CSV"
```python
df.to_csv("ilostat_data.csv", index=False)
```
=== "Parquet"
```python
df.to_parquet("ilostat_data.parquet", index=False)
```
Next steps¶
-
:material-database: Bulk data access
Explore advanced filtering, labels, sources and observation notes.
-
:material-network: SDMX
Explore SDMX data, structures, codelists and dataflows.
-
:material-harddisk: Cache management
Manage downloaded resources and optimize performance.
-
:material-code-braces: API reference
Consult function signatures, parameters and return types.