This Python library contains KUDAF metadata schema definitions and logic that is common and applicable to other KUDAF Python packages
Project description
Kudaflib - The KUDAF Metadata Library and CLI tools
This package contains the following elements:
-
Metadata schema definitions for the Kudaf platform, adhering to global standards: a. DCAT-AP-NO standard: Catalog and Dataset metadata, compatible with the requirements of the Norwegian Fellesdatakatalog b. RAIRD standard: Variable metadata
-
A CLI tool to generate and upload metadata to the KUDAF data-sharing platform.
It was developed by Sikt - Kunnskapssektorens tjenesteleverandør under the KUDAF initiative to enable a Data Producer to make small-file data available on the KUDAF data-sharing platform.
About KUDAF
KUDAF - Kunnskapssektorens datafelleskap skal sørge for tryggere, enklere og bedre deling av data. Les mer om KUDAF.
High-level workflow for Data Source administrators (Beta version)
Fra dataprodusent til datatilbyder
Feide Kundeportal - Datadeling (Nosrk)
Local installation instructions (Linux/Mac)
Make sure Python3 is installed on your computer (versions from 3.8 up to 3.11 should work fine)
$ python3 --version
Navigate to the folder chosen to contain this project
$ cd path/to/desired/folder
Create a Python virtual environment and activate it (highly recommended so as not to disturb the computer's global Python installation)
$ python3 -m venv .venv
This created the virtualenv under the hidden folder .venv
Activate it with:
$ source .venv/bin/activate
Install Kudaf Metadata Tools and other required Python packages
$ pip install kudaflib
Kudaflib CLI operation
Navigate to the project directory and activate the virtual environment (if not already activated):
$ source .venv/bin/activate
The kudaf-generate command should be now activated. This is the main entry point to the CLI's functionalities.
There are two sub-commands available:
1.- metadata: Generates JSON (RAIRD) metadata for Kudaf Variables
2.- upload: Uploads metadata to the Kudaf-Metadata back-end (choice of 3 environments)
Displaying the help menus
$ kudaf-generate --help
Usage: kudaf-generate [OPTIONS] COMMAND [ARGS]...
Kudaf Metadata CLI Tools
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ metadata Generate Variables/UnitTypes Metadata |
| upload Create metadata in the KUDAF Metadata Backend (Catalogs, Datasets, UnitTypes and variables) │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
We can obtain help on a sub-command as well:
$ kudaf-generate upload --help
Usage: kudaf-generate upload [OPTIONS]
Upload metadata to the KUDAF Metadata Backend (Catalogs, Datasets, UnitTypes and Variables)
If any of the optional directories is not specified, the current directory is used as default.
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --config-yaml-path PATH **Absolute path** to the YAML configuration file [default: /home/me/current/directory/config.yaml] │
│ --output-metadata-dir PATH **Absolute path** to directory where the Metadata files are to be written to [default: /home/me/current/directory] │
│ --target-environment TEXT Please enter Kudaf-Metadata's **Target Environment (DEV, STAGING, PRODUCTION**) [default: DEV] │
│ --api-key TEXT Kudaf Metadata API Key [default: None] │
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
$ kudaf-generate metadata --help
Usage: kudaf-generate metadata [OPTIONS]
Generate Variables/UnitTypes Metadata
JSON metadata files ('variables.json' and maybe 'unit_types.json') will be written to the (optionally) given output directory
If any of the optional directories is not specified, the current directory is used as default.
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --config-yaml-path PATH **Absolute path** to the YAML configuration file [default: /home/me/current/directory/config.yaml] │
│ --output-metadata-dir PATH **Absolute path** to directory where the Metadata files are to be written to [default: /home/me/current/directory] │
│ --help Show this message and exit. │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Uploading KUDAF metadata to the Kudaf-metadata back-end (3 target environments: DEV, STAGING, PRODUCTION)
$ kudaf-generate upload --config-yaml-path "</home/me/path/to/config.yaml>"
Target environment [DEV]: DEV
Api key: <EnterYourAPIKeyHere>
...[sample output below]..
──────────────────────────────────────────────────────────────────────── ⚡ Starting KUDAF Metadata upload... 🤹 ──────────────────────────────────────────────
Uploading Metadata to KUDAF system @ 👉 http://localhost:8000/
🔐 Catalog Database for statistikk om høyere utdanning (DBH) already exists --> skipping creation
⭐ -> UNIT TYPE: HKDIR_STUDIESOKNAD from Catalog: Database for statistikk om høyere utdanning (DBH) CREATED in Kudaf-Metadata @ http://localhost:8000/
💩 Resource not found at URL: URL('http://localhost:8000/api/v1/datasets/')
⭐ -> DATASET: HK-dir DBH Studiesøknader from Catalog: Database for statistikk om høyere utdanning (DBH) CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_UTDANNINGSBAKGRUNN from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_TILBUD_OPPTAK from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_SPRAAKPOENG from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_REALFAGSPOENG from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_PRIORITET from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_OPPTAKSTYPE from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_MOTT from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_KVOTE from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_KVALIFISERT from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_KOMPETANSE from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_KARAKTERPOENG from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_INSTKODE from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_FNR from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_ANDRE_POENG from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
⭐ --> VARIABLE: HKDIR_DBH_SOKNAD_AKSEPTERT from Dataset: HK-dir DBH Studiesøknader CREATED in Kudaf-Metadata @ http://localhost:8000/
───────────────────────────────────────────────────────────────────────────────────── ⚡ Success! 🥳 ────────────────────────────────────────────────────────────
Generating Variables metadata only from a YAML configuration file
$ kudaf-generate metadata --config-yaml-path /home/me/path/to/config.yaml --output-metadata-dir /home/me/path/to/metadata/folder
Creating a YAML configuration file
Click here for a basic YAML syntax tutorial
Example YAML configuration file
The following file is included in the package and can be found in the kudaflib/config folder:
config_example.yaml
---
# This is an example configuration file for the Kudaflib API.
#
# The fields are written in YAML format, which is a human-readable data serialization standard.
# (See https://yamline.com/tutorial/)
#
# The fields are structured in a hierarchy, with each level separated by a colon and a space.
# Please be aware that the field names are case-sensitive and must be written exactly as shown.
# It contains the basic metadata fields necessary for describing:
# - One CATALOG, containing:
# - One or more UNIT TYPES for this specific Catalog (different from the global unit types)
# and applicable to the Variables in this Catalog
# - One or more DATASETS, containing:
# - One or more VARIABLES (3 in this case)
catalogs:
- title: "Short name for this catalog"
description: "Description of this catalog"
publisher:
name: "Name of the organization that publishes this catalog"
identifier: "9-digit Norwegian Organization number (BRREG)"
type: "http://purl.org/adms/publishertype/NationalAuthority"
contactPoint:
name: "Name of the contact person/organization"
identifier: "9-digit Norwegian Organization number (BRREG), if applicable"
mbox: "post@person.no"
url: "https://org.no"
unittypes: # Bare nødvendig hvis forskjellig fra de globale enhetstypene: PERSON/VIRKSOMHET/KOMMUNE/FYLKE
- shortName: MIN_ENHETSTYPE1 # Vises ved siden av nøkkelikonet i Frontends Prøverom
name: Kort identifikasjonsetikett # Merker den blå boksen med variabler som deler UnitType i Prøverom
description: Detaljert beskrivelse av denne enhetstypen
dataType: LONG # En av STRING/DATE/LONG/DOUBLE
- shortName: MIN_ENHETSTYPE2 # Vises ved siden av nøkkelikonet i Frontends Prøverom
name: Kort identifikasjonsetikett # Merker den blå boksen med variabler som deler UnitType i Prøverom
description: Detaljert beskrivelse av denne enhetstypen
dataType: LONG # En av STRING/DATE/LONG/DOUBLE
datasets:
- identifier: "9efe2de1-1093-4662-a8cb-fd7907bae9bc"
title: "Short title of this Dataset"
description: "Full description of the Dataset"
publisher:
name: "Name of the organization that publishes this catalog"
identifier: "9-digit Norwegian Organization number (BRREG)"
type: "http://purl.org/adms/publishertype/NationalAuthority"
contactPoint:
name: "Name of the contact person"
identifier: "9-digit Norwegian Organization number (BRREG)"
mbox: "post@person.no"
url: "https://org.no"
spatial:
- Norge
theme:
- https://psi.norge.no/los/tema/hoyere-utdanning # Eksempel
- http://publications.europa.eu/resource/authority/data-theme/EDUC # Eksempel
keyword:
no: "høyere utdanning" # Eksempel
en: "higher education" # Eksempel
variables:
- name: VARIABELENS_NAVN
temporalityType: FIXED # En av FIXED/EVENT/STATUS/ACCUMULATED
sensitivityLevel: NONPUBLIC # En av PUBLIC/NONPUBLIC
populationDescription:
- Beskrivelse av populasjonen som denne variabelen måler
spatialCoverageDescription:
- Norge
- Annen geografisk beskrivelse som gjelder disse dataene
subjectFields:
- Temaer/konsepter/begreper som disse dataene handler om
identifierVariables:
- unitType: MIN_ENHETSTYPE1 # Bruk shortName feltet i UnitType definisjonen ovenfor (kan også være en av de globale enhetstypene: PERSON/VIRKSOMHET/KOMMUNE/FYLKE)
measureVariables:
- label: Kort etikett på hva denne variabelen måler/viser
description: Detaljert beskrivelse av hva denne variabelen måler/viser
dataType: STRING # En av STRING/LONG/DATE/DOUBLE
- name: VARIABELENS_NAVN_ACCUM
temporalityType: ACCUMULATED # En av FIXED/EVENT/STATUS/ACCUMULATED
sensitivityLevel: NONPUBLIC # En av PUBLIC/NONPUBLIC
populationDescription:
- Beskrivelse av populasjonen som denne variabelen måler
spatialCoverageDescription:
- Norge
- Annen geografisk beskrivelse som gjelder disse dataene
subjectFields:
- Temaer/konsepter/begreper som disse dataene handler om
identifierVariables:
- unitType: MIN_ENHETSTYPE2 # Bruk shortName feltet i UnitType definisjonen ovenfor (kan også være en av de globale enhetstypene: PERSON/VIRKSOMHET/KOMMUNE/FYLKE)
measureVariables:
- label: Kort etikett på hva denne variabelen måler/viser
description: Detaljert beskrivelse av hva denne variabelen måler/viser
dataType: STRING # En av STRING/LONG/DATE/DOUBLE
- name: LENKEVAR_ID-NØKKEL_MÅLE-NOKKEL # Eksempel på en lenkevariabel, som kobler to forskjellige enhetstyper
temporalityType: FIXED # En av FIXED/EVENT/STATUS/ACCUMULATED
sensitivityLevel: PUBLIC # En av PUBLIC/NONPUBLIC
populationDescription:
- Beskrivelse av populasjonen som denne variabelen måler
spatialCoverageDescription:
- Norge
- Annen geografisk beskrivelse som gjelder disse dataene
subjectFields:
- Temaer/konsepter/begreper som disse dataene handler om
identifierVariables:
- unitType: VIRKSOMHET # Kan også være en av de shortName feltet i UnitType definisjoner ovenfor
measureVariables:
- label: Kort etikett på hva denne variabelen måler/viser
description: Detaljert beskrivelse av hva denne variabelen måler/viser
unitType: MIN_ENHETSTYPE1 # Bruk shortName feltet i UnitType definisjonen ovenfor (kan også være en av de globale enhetstypene: PERSON/VIRKSOMHET/KOMMUNE/FYLKE)
dataType: LONG # En av STRING/LONG/DATE/DOUBLE
...
For developers: How to create a local development environment
Download the package to your computer
Option A: Installation from repository:
Open up a Terminal window and clone the repo locally:
$ git clone https://gitlab.sikt.no/kudaf/kudaflib.git
Option B: Installation from source:
-
Open up your browser and navigate to the project's GitLab page:
https://gitlab.sikt.no/kudaf/kudaflib -
Once there, download a ZIP file with the source code
-
Move the zipped file to whichever directory you want to use for this installation
-
Open a Terminal window and navigate to the directory where the zipped file is
-
Unzip the downloaded file, it will create a folder called
kudaflib-main -
Switch to the newly created folder
$ cd path/to/kudaflib-main
Make sure Python3 is installed on your computer (versions from 3.8 up to 3.11 should work fine)
$ python3 --version
Install Poetry (Python package and dependency manager) on your computer
Full Poetry documentation can be found here: https://python-poetry.org/docs/
The official installer should work fine on the command line for Linux, macOS and Windows:
$ curl -sSL https://install.python-poetry.org | python3 -
If the installation was successful, configure this option:
$ poetry config virtualenvs.in-project true
Mac users: Troubleshooting
In case of errors installing Poetry on your Mac, you may have to try installing it with pipx . But to install that, we need to have Homebrew installed first.
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(Homebrew documentation: https://brew.sh/)
Once Homebrew is installed, proceed to install pipx:
$ brew install pipx
$ pipx ensurepath
Finally, install Poetry :
$ pipx install poetry
Create a Python virtual environment and activate it
$ python3 -m venv .venv
This created the virtualenv under the hidden folder .venv
Activate it with:
$ source .venv/bin/activate
Install Kudaf Datasource Tools and other required Python packages
$ poetry install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kudaflib-0.2.1.tar.gz.
File metadata
- Download URL: kudaflib-0.2.1.tar.gz
- Upload date:
- Size: 209.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.8.0-51-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8800aed5a31e702e02011fa9bfc2df80bae07593158c95e13a68c95a1abb8d39
|
|
| MD5 |
00f8c836ab744c360d39851a75948cb9
|
|
| BLAKE2b-256 |
e84f5e236b72dfe369a3234350c5809bbf9deda3d57245fd2038b38c0898bf1e
|
File details
Details for the file kudaflib-0.2.1-py3-none-any.whl.
File metadata
- Download URL: kudaflib-0.2.1-py3-none-any.whl
- Upload date:
- Size: 213.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/6.8.0-51-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
178a804c19725eb1ac9e3eecfd17b699e9ade15ab0c896d93553057c6618b85e
|
|
| MD5 |
08b5290a8fee9ddaad98554fa77801b2
|
|
| BLAKE2b-256 |
2d28a5e3ab05e3ba1f338cda40a74fcfbd96da26e03e378ca4d19dcd49d91b50
|