Skip to content
README.md 8.24 KiB
Newer Older
# Metadata Auto R Library

## Introduction

This repository aims to simplify the access to the [Swiss Federal Statistical Office](https://www.bfs.admin.ch/bfs/en/home.html) metadata. 
Following the implementation in the [interoperability platform](https://www.i14y.admin.ch) and the [SIS portal](https://sharepoint.admin.ch/edi/bfs/fr-ch/News/Pages/go-life-neues-sis-portals.aspx), the APIs are made available here in R.
This public library is made available for the internal FSO staff, the federal administration and for external actors.
## Installation
You can install the library with
## Functionnalities
Based on the metadata that you want, you will call certain functions and parameters. 
In the first part, we describe the API available from everywhere, then we describe the API available only from within the confederation network.
### Available everywhere with the interoperability plateform (i14y)
#### Codelists
1. Export a codelist based on an identifier
```
response = get_codelist(identifier, export_format="SDMX-ML", version_format=2.1, annotations=False)
```
    Parameters:
        - identifier (str): the codelist's identifier
        - export_format (str, default="SDMX-ML"): the export's format. 
            Available are CSV, XLSX, SDMX-ML or SDMX-JSON.
        - version_format (float, default=2.1): the export format's version 
            (2.0 or 2.1 when format is SDMX-ML).
        - annotations (bool, default=False): flag to include annotations
    Returns:
        - response (pd.DataFrame or dict) based on the export format
            - a pd.DataFrame if export_format was CSV or XLSX
            - a dictionnary if export_format was SDMX-ML or SDMX-JSON.
#### ContentConfigurations
1. Return the display information for the available configured content
```
response = get_content_creation()
```
    Returns:
        - response (dict): the configured content's display information
2. Return an identifier's nomenclature's information
```
response = get_identifier_content(identifier)
```

    Parameters:
        - identifier (str): the nomenclature's identifier
    Returns:
        - response (dict): the nomenclature's information


#### Datasets
1. Get the dataset description
```
response = get_dataset_description(identifier, language='fr')
```

    Parameters:
        - identifier (str): the nomenclature's identifier
        - language (str, default='fr'): the language of the response data. 
            Available are 'fr', 'de', 'it', 'en'.
    Returns:
        - response: description's dictionnary

2. Get the dataset information
```
response = get_dataset_information(identifier, language='fr')
```

    Parameters:
        - identifier (str): the nomenclature's identifier
        - language (str, default='fr'): the language of the response data. 
            Available are 'fr', 'de', 'it', 'en'.
    Returns:
        - response: information's dictionnary

#### Data Structures
1. Get the data structure
```
response = get_data_structure(identifier, language='fr')
```

    Parameters:
        - identifier (str): the nomenclature's identifier
        - language (str, default='fr'): the language of the response data. 
            Available are 'fr', 'de', 'it', 'en'.
    Returns:
        - response: data structure's dictionnary


#### Nomenclatures

1. Get the nodes of a path within a nomenclature
```
response = get_nomenclature_path_nodes(identifier, path, filters={}, language='fr')
```

    Parameters:
        - identifier (str): the nomenclature's identifier
        - path (str): the path leading to the nodes
        - filters (dict, default={}): the filters to apply
        - language (str, default='fr'): the language of the response data. 
            Available are 'fr', 'de', 'it', 'en'.
    Returns:
        - response: dictionnary of the nodes
   
2. Export one level of a nomenclature
```
response = get_nomenclature_one_level(identifier, level_number, filters={}, language='fr', annotations=False)
```

    Parameters:
        - identifier (str): nomenclature's identifier
        - level_number (int): level to export
        - filter (default={}): additionnal filters
        - language (str, default='fr'): response data's language 
            Available are 'fr', 'de', 'it', 'en'.
        - annotations (bool, default=False): flag to include annotations
    Returns:
        - response (pd.DataFrame): dataframe with 3 columns 
            (Code, Parent and Name in the selected language)


3. Export multiple levels of a nomenclature (from `level_from` to `level_to`)
```
response = get_nomenclature_multiple_levels(identifier, level_from, level_to, filters={}, language='fr', annotations=False)
```

    Parameters:
        - identifier (str): nomenclature's identifier
        - level_from (int): the 1st level to include
        - level_to (int): the last level to include
        - filter (default={}): additionnal filters
        - language (str, default='fr'): response data's language 
            Available are 'fr', 'de', 'it', 'en'.
        - annotations (bool, default=False): flag to include annotations
    Returns:
        - response (pd.DataFrame): dataframe columns from `level_from` to `level_to` codes


4. Search query within a nomenclature
```
response = query_nomenclature(identifier, query, page_number, page_size, fiters={}, language='fr')
```

    Parameters:
        - identifier (str): the nomenclature's identifier
        - query (str): the search query
        - page_number (int): the number of the result page to return
        - page_size (int): the size of each page result
        - filter (default={}): additionnal filters
        - language (str, default='fr'): response data's language 
            Available are 'fr', 'de', 'it', 'en'.
    Returns:
        - response (dict): the query result


### Available only internally (Intern to confederation or via VPN)

All these function start with `dcat_`

#### Agents
1. List all agents
```
response = dcat_list_all_agents()
```

    Returns:
        - response (dict): all agents

2. Get the agent with the corresponding agent id
```
response = dcat_get_agent_from_id(agent_id)
```

    Parameters:
        - agent_id (str): agent's id
    Returns:
        - response (dict): agent with this id

#### Datasets
1. List all datasets
```
response = dcat_list_all_datasets()
```

    Returns:
        - response (dict): list of all datasets
        

2. Get all distributions for the dataset with the corresponding dataset id
```
response = dcat_get_distributions_from_dataset_id(dataset_id)
```

    Parameters:
        - dataset_id (str): dataset's id
    Returns:
        - response (dict): distributions for the dataset with dataset's id

3. Get the dataset with the corresponding id
```
response = dcat_get_dataset_from_id(dataset_id)
```

    Parameters:
        - dataset_id (str): dataset's id
    Returns:
        - response (dict): the dataset
        

4. Get the dataset with the corresponding identifier
```
response = dcat_get_dataset_from_identifier(identifier: str)
```

    Parameters:
        - identidier (str): dataset's identifier
    Returns:
        - response (dict): the dataset

5. Get all distributions for the dataset with the corresponding dataset identifier.
```
response = dcat_get_distributions_from_dataset_identifier(identifier)
```

    Parameters:
        - identidier (str): dataset's identifier
    Returns:
        - response (dict): all distributions for the dataset with the corresponding identifier

#### Distribution
1. List all distributions
```
response = dcat_list_all_distributions()
```

    Returns:
        - response (dict): all distributions
        
2. Get the distribution with the corresponding id
```
response = dcat_get_distribution_from_id(distribution_id)
```

    Parameters:
        - distribution_id (str): distribution's id
    Returns:
        - response (dict): the distribution



As the APIs continue to be implemented, further functionnalities will be added.

## Background
All the APIs made available in this library are also documented in Swagger UI should you want to do more experiments through a UI.
- [Here](https://www.i14y.admin.ch/api/index.html) for APIs of the interoperability platform (public).
- [Here](https://dcat.app.cfap02.atlantica.admin.ch/api/index.html) for dcat APIs (internal to configuration).

## Example

Examples for each API are provided in the [R Markdown](https://TODO).