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.
## 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.
1. Return the display information for the available configured content
```
response = get_content_creation()
```
Returns:
- response (dict): the configured content's display information
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
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).