Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fabian Santi
Metadata Auto Python Library
Commits
8edf8d29
Commit
8edf8d29
authored
Oct 21, 2021
by
Fabian Santi
Browse files
Auto-saving for fabian.santi on branch class_apis from commit
77ac36b7
parent
3d571861
Pipeline
#269563
failed with stage
in 37 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
fso_metadata/examples.ipynb
View file @
8edf8d29
%% Cell type:markdown id:
fcad4b17
tags:
%% Cell type:markdown id: tags:
# Example notebook
In this notebook, we show one example per possible API call.
%% Cell type:code id:
a529fab5-af2f-4439-b98e-13d814b00a94
tags:
%% Cell type:code id: tags:
```
python
import
fso_metadata
```
%% Cell type:code id:486bc684-f4a1-4b26-80ff-c156c51fdb97 tags:
%%%% Output: error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-4875aac72486> in <module>
----> 1 import fso_metadata
ModuleNotFoundError: No module named 'fso_metadata'
%% Cell type:code id: tags:
```
python
# from api_call import (
from
fso_metadata
import
(
dcat_get_agent_from_id
,
dcat_get_dataset_from_id
,
dcat_get_dataset_from_identifier
,
dcat_get_distributions_from_dataset_id
,
dcat_get_distributions_from_dataset_identifier
,
dcat_get_distribution_from_id
,
dcat_list_all_agents
,
dcat_list_all_datasets
,
dcat_list_all_distributions
,
get_codelist
,
get_content_configuration
,
get_data_structure
,
get_dataset_description
,
get_dataset_information
,
get_identifier_content
,
get_nomenclature_path_nodes
,
get_nomenclature_one_level
,
get_nomenclature_multiple_levels
,
query_nomenclature
)
```
%% Cell type:markdown id:94312182-0616-4938-8d82-d666611bf64d tags:
%%%% Output: error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-2ab115b4c380> in <module>
1 # from api_call import (
----> 2 from fso_metadata import (
3 dcat_get_agent_from_id,
4 dcat_get_dataset_from_id,
5 dcat_get_dataset_from_identifier,
ModuleNotFoundError: No module named 'fso_metadata'
%% Cell type:markdown id: tags:
## Available everywhere with the interoperability plateform (i14y)
%% Cell type:markdown id:
bdd766a5-c013-449c-9fd4-7356835396af
tags:
%% Cell type:markdown id: tags:
[
i14y Swagger UI
](
https://www.i14y.admin.ch/api/index.html
)
%% Cell type:markdown id:
446b07a4
tags:
%% Cell type:markdown id: tags:
### Code List
%% Cell type:code id:
317c3e55
tags:
%% Cell type:code id: tags:
```
python
# Get a codelist pd.Serie based on an identifier
codelist
=
get_codelist
(
identifier
=
'CL_NOGA_SECTION'
,
export_format
=
"SDMX-ML"
,
version_format
=
2.1
,
annotations
=
True
)
codelist
.
head
(
5
)
```
%%%% Output: execute_result
CL_NOGA_SECTION
A AGRICULTURE, FORESTRY AND FISHING
B MINING AND QUARRYING
C MANUFACTURING
D ELECTRICITY, GAS, STEAM AND AIR-CONDITIONING S...
E WATER SUPPLY; SEWERAGE, WASTE MANAGEMENT AND R...
Name: NOGA Section, dtype: object
%% Cell type:markdown id:
b0029468
tags:
%% Cell type:markdown id: tags:
### Content Creation
%% Cell type:code id:
5bf187c8
tags:
%% Cell type:code id: tags:
```
python
# Get the display information for the available configured content
content
=
get_content_configuration
()
content
```
%%%% Output: execute_result
[{'default': True,
'identifier': 'HCL_CH_ISCO_19_PROF',
'items': [],
'label': 'CH-ISCO-19',
'skipRoute': False}]
%% Cell type:code id:
88581bea
tags:
%% Cell type:code id: tags:
```
python
# Get a nomenclature information based on its identifier
identifier_content
=
get_identifier_content
(
identifier
=
'HCL_CH_ISCO_19_PROF'
)
identifier_content
```
%%%% Output: execute_result
{'agencyIdentifier': 'FSO',
'controllerName': 'Nomenclatures',
'descriptionIdentifier': 'HCL_CH_ISCO_19_PROF',
'exportFormats': ['CSV', 'XLSX'],
'exportLanguages': ['de', 'fr', 'it', 'en', 'rm'],
'exportLevels': ['1', '2', '3', '4', '5', '6'],
'exportTypes': {'Single': 'levelexport', 'Multi': 'multilevels'},
'filters': [{'identifier': 'AF_ACTIVE', 'values': ['0', '1']},
{'identifier': 'AFC_ISCO_REDUCED_LIST', 'values': ['1']},
{'identifier': 'AFC_ISCO_DUPLICATE', 'values': ['0']},
{'identifier': 'AF_LEARNED_OR_PRACTICED', 'values': ['1', '2']},
{'identifier': 'AF_AVAM', 'values': ['1']}],
'hasAnnotations': True,
'identifier': 'HCL_CH_ISCO_19_PROF',
'type': 'Nomenclature'}
%% Cell type:markdown id:
42d2d24c-3e0b-40b6-a4b3-5e409345b449
tags:
%% Cell type:markdown id: tags:
### Datasets
%% Cell type:code id:
b1d312b6-4b66-41aa-8d2e-4441e803ba07
tags:
%% Cell type:code id: tags:
```
python
# Get the dcat dataset description
dataset_description
=
get_dataset_description
(
identifier
=
'HCL_NOGA'
,
language
=
'de'
)
dataset_description
[
'contactPoint'
][
0
]
```
%%%% Output: execute_result
{'adrWork': {'cultureCode': 'de',
'text': "Unternehmensregisterdaten URD\nEspace de l'Europe 10\nCH-2010 Neuchâtel\nSchweiz"},
'child': 0,
'emailInternet': 'noga@bfs.admin.ch',
'fn': {'cultureCode': 'de', 'text': 'Bundesamt für Statistik'},
'note': {'cultureCode': 'de',
'text': 'Von Montag bis Freitag\n8.30–11.30 Uhr und 14.00–16.00 Uhr'},
'org': {'cultureCode': None, 'text': None},
'telWorkVoice': '+41 58 463 65 23'}
%% Cell type:code id:
36e4a8c2-097f-4c1d-9dc3-b1c86f855ffa
tags:
%% Cell type:code id: tags:
```
python
# Get the dcat dataset information
dataset_information
=
get_dataset_information
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
language
=
'fr'
)
dataset_information
[
0
][
'accessUrl'
]
```
%%%% Output: execute_result
[{'href': 'https://www.i14y.admin.ch/api/nomenclatures/HCL_CH_ISCO_19_PROF/levelexport/XLSX?level=6&annotations=true',
'label': 'https://www.i14y.admin.ch/api/nomenclatures/HCL_CH_ISCO_19_PROF/levelexport/XLSX?level=6&annotations=true'}]
%% Cell type:markdown id:
c945eee9-8908-4012-b022-af419d5999b9
tags:
%% Cell type:markdown id: tags:
### Data Structures
%% Cell type:code id:
56e92700-881f-48af-81d4-1ed622b87400
tags:
%% Cell type:code id: tags:
```
python
# Get the data structure
data_structure
=
get_data_structure
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
language
=
'it'
)
data_structure
```
%%%% Output: execute_result
{'type': 'https://httpstatuses.com/404',
'title': 'Not Found',
'status': 404,
'detail': 'DataStructure with type Nomenclature and identifiers HCL_CH_ISCO_19_PROF/HR_CH_ISCO_19_PROF is not supported.',
'traceId': '|f51d8358-4dd7c2b42061dbb5.'}
%% Cell type:markdown id:
99f3ee98
tags:
%% Cell type:markdown id: tags:
### Nomenclature
%% Cell type:code id:
ddd5eb9f
tags:
%% Cell type:code id: tags:
```
python
# Get the nodes of a path within a nomenclature, add filters to get more specific results
filters
=
{
'code'
:
False
}
# TODO: ask what filters are and how they work
path_nodes
=
get_nomenclature_path_nodes
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
path
=
'.'
,
filters
=
filters
,
language
=
'fr'
)
path_nodes
```
%%%% Output: execute_result
[{'annotations': [],
'code': '0',
'hasChilds': True,
'name': {'cultureCode': 'fr', 'text': 'Professions militaires'}},
{'annotations': [],
'code': '1',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Directeurs, cadres de direction et gérants'}},
{'annotations': [],
'code': '2',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Professions intellectuelles et scientifiques'}},
{'annotations': [],
'code': '3',
'hasChilds': True,
'name': {'cultureCode': 'fr', 'text': 'Professions intermédiaires'}},
{'annotations': [],
'code': '4',
'hasChilds': True,
'name': {'cultureCode': 'fr', 'text': 'Employés de type administratif'}},
{'annotations': [],
'code': '5',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Personnel des services directs aux particuliers, commerçants et vendeurs'}},
{'annotations': [],
'code': '6',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Agriculteurs et ouvriers qualifiés de l’agriculture, de la sylviculture et de la pêche'}},
{'annotations': [],
'code': '7',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Métiers qualifiés de l’industrie et de l’artisanat'}},
{'annotations': [],
'code': '8',
'hasChilds': True,
'name': {'cultureCode': 'fr',
'text': 'Conducteurs d’installations et de machines, et ouvriers de l’assemblage'}},
{'annotations': [],
'code': '9',
'hasChilds': True,
'name': {'cultureCode': 'fr', 'text': 'Professions élémentaires'}}]
%% Cell type:code id:
dbc2f301
tags:
%% Cell type:code id: tags:
```
python
# Get one level of a nomenclature in a dataframe
filters
=
{
'code'
:
'1'
}
# TODO: ask what filters are and how they work
single_level
=
get_nomenclature_one_level
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
filters
=
filters
,
level_number
=
2
,
language
=
'fr'
,
annotations
=
False
)
single_level
.
head
()
```
%%%% Output: execute_result
Code Parent Name_fr
0 01 0 Officiers des forces armées
1 02 0 Sous-officiers des forces armées
2 03 0 Autres membres des forces armées
3 10 1 Directeurs, cadres de direction et gérants, sip
4 11 1 Directeurs généraux, cadres supérieurs et memb...
%% Cell type:code id:
94499315
tags:
%% Cell type:code id: tags:
```
python
# Get multiple levels of a nomenclature in a dataframe
filters
=
{
'code'
:
'1'
}
# TODO: ask what filters are and how they work
multiple_levels
=
get_nomenclature_multiple_levels
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
level_from
=
1
,
level_to
=
4
,
filters
=
filters
,
language
=
'en'
,
annotations
=
True
)
multiple_levels
.
head
(
5
)
```
%%%% Output: execute_result
Major_groups Sub-major_groups Minor_groups Unit_groups Code Name_en
0 0 NaN NaN NaN 0 NaN
1 0 01 NaN NaN 01 NaN
2 0 01 011 NaN 011 NaN
3 0 01 011 0110 0110 NaN
4 0 02 011 0110 02 NaN
%% Cell type:code id:
7fa4060a
tags:
%% Cell type:code id: tags:
```
python
# Search a query within a nomenclature
filters
=
{
'code'
:
'1'
}
# TODO: ask what filters are and how they work
query_result
=
query_nomenclature
(
identifier
=
'HCL_CH_ISCO_19_PROF'
,
query
=
'SELECT *'
,
page_number
=
5
,
page_size
=
2
,
filters
=
filters
,
language
=
'fr'
)
query_result
[
0
][
'annotations'
][
0
]
```
%%%% Output: execute_result
{'identifier': None,
'text': {'cultureCode': 'fr', 'text': 'Divisionnaire'},
'title': '',
'type': 'GENDER_M',
'url': ''}
%% Cell type:markdown id:
c2c9dd0e
tags:
%% Cell type:markdown id: tags:
## Available only internally (Intern to confederation or via VPN)
[
Dcat Swagger UI
](
https://dcat.app.cfap02.atlantica.admin.ch/api/index.html
)
%% Cell type:markdown id:
82d1b717-6fa5-46d1-8534-e67c49db2ea1
tags:
%% Cell type:markdown id: tags:
### Agent
%% Cell type:code id:
6b9c8a86
tags:
%% Cell type:code id: tags:
```
python
# List all agents
agents_list
=
dcat_list_all_agents
()
agents_list
```
%% Cell type:code id:
ce5c4961
tags:
%% Cell type:code id: tags:
```
python
# Get the agent with the corresponding agent id
agent
=
dcat_get_agent_from_id
(
agent_id
=
'3fa85f64-5717-4562-b3fc-2c963f66afa6'
)
agent
```
%% Cell type:markdown id:
61f717da
tags:
%% Cell type:markdown id: tags:
### Dataset
%% Cell type:code id:
b98d4a5b
tags:
%% Cell type:code id: tags:
```
python
# List all datasets
datasets_list
=
dcat_list_all_datasets
()
datasets_list
```
%% Cell type:code id:
62a94c03
tags:
%% Cell type:code id: tags:
```
python
# Get all distributions for the dataset with the corresponding dataset id
dataset_distributions
=
dcat_get_distributions_from_dataset_id
(
dataset_id
=
'xxx'
)
dataset_distributions
```
%% Cell type:code id:
37c91e18
tags:
%% Cell type:code id: tags:
```
python
# Get the dataset with the corresponding id
dataset
=
dcat_get_dataset_from_id
(
dataset_id
=
'xxx'
)
dataset
```
%% Cell type:code id:
799203a0
tags:
%% Cell type:code id: tags:
```
python
# Get the dataset with the corresponding identifier
dataset
=
dcat_get_dataset_from_identifier
(
identifier
=
'xxx'
)
dataset
```
%% Cell type:code id:
73a44a0c
tags:
%% Cell type:code id: tags:
```
python
# Get all distributions for the dataset with the corresponding dataset identifier
distribution
=
dcat_get_distributions_from_dataset_identifier
(
identifier
=
'xxx'
)
distribution
```
%% Cell type:markdown id:
158a5f1c
tags:
%% Cell type:markdown id: tags:
### Distributions
%% Cell type:code id:
835bd843
tags:
%% Cell type:code id: tags:
```
python
# List all distributions
distributions_list
=
dcat_list_all_distributions
()
distributions_list
```
%% Cell type:code id:
9d642a0d
tags:
%% Cell type:code id: tags:
```
python
# Get the distribution with the corresponding id
distribution
=
dcat_get_distribution_from_id
(
distribution_id
=
'xxx'
)
distribution
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment