A library for transforming an openAPI file to one or more dcat:DataService
Project description
oastodcat
A small Python library to transform an openAPI file to a dcat:DataService
At this moment we support all 3.0.x versions of (The OpenAPI specification)[https://github.com/OAI/OpenAPI-Specification]
Usage
Install
% pip install oastodcat
Getting started
Example usage:
import yaml
import requests
from datacatalogtordf import Catalog
from oastodcat import OASDataService
# Create catalog object
catalog = Catalog()
catalog.identifier = "http://example.com/catalogs/1"
catalog.title = {"en": "A dataset catalog"}
catalog.publisher = "https://example.com/publishers/1"
# Create a dataservice based on an openAPI-specification:
url = ("https://raw.githubusercontent.com/"
"OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml"
)
oas = yaml.safe_load(requests.get(url).text)
identifier = "http://example.com/dataservices/{id}"
oas_spec = OASDataService(url, oas, identifier)
#
# Add dataservices to catalog:
for dataservice in oas_spec.dataservices:
catalog.services.append(dataservice)
get dcat representation in turtle (default)
dcat = catalog.to_rdf()
# Get dcat representation in turtle (default)
dcat = catalog.to_rdf()
print(dcat.decode())
Mapping
The following table shows how an openAPI specification is mapped to a dcat:DataService:
(Only dcat:DataService properties are shown.)
dcat:DataService | RDF property | openAPI v 3.0.x | Note |
---|---|---|---|
endpoint description | dcat:endpointDescription | ||
endpoint URL | dcat:endpointURL | servers.url | [1] |
serves dataset | n/a | ||
access rights | |||
conforms to | dct:conformsTo | ||
contact point | dcat:contactPoint | info.contact | |
creator | |||
description | dct:description | info.description | |
has policy | |||
identifier | n/a | ||
is referenced by | |||
keyword/tag | |||
landing page | dcat:landingPage | externalDocs | |
license | dct:license | info.license.url | |
resource language | |||
relation | |||
rights | |||
qualified relation | |||
publisher | dct:publisher | ||
release date | |||
theme/category | |||
title | dct:title | info.title | |
type/genre | |||
update/modification date | |||
qualified attribution | |||
media type | dcat:mediaType | <it's complicated> |
[1] For each url in the servers object array, an instance of dcat:DataService will be created.
Development
Requirements
- python3
- pyenv (recommended)
- pipx (recommended)
- poetry
- nox
- nox-poetry
% pipx install poetry==1.0.5
% pipx install nox==2019.11.9
% pipx inject nox nox-poetry
Install
% git clone https://github.com/Informasjonsforvaltning/oastodcat.git
% cd oastodcat
% pyenv install 3.8.6
% pyenv install 3.7.9
% pyenv install 3.9.0
% pyenv local 3.9.0 3.8.3 3.7.7
% poetry install
Run all sessions
% nox
Run all tests with coverage reporting
% nox -rs tests
Debugging
You can enter into Pdb by passing --pdb
to pytest:
nox -rs tests -- --pdb
You can set breakpoints directly in code by using the function breakpoint()
.
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
File details
Details for the file oastodcat-2.0.0a4.tar.gz
.
File metadata
- Download URL: oastodcat-2.0.0a4.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8de15c8cd4a85bcfa48eeb2a4167c94bf316aab257d9a24ba85369431660972c |
|
MD5 | 53bf97b1fe2740caed883818fa2bd719 |
|
BLAKE2b-256 | 20a7ebcd9c213c2414975f44058088732e31ce9af6ab783f46af32e300de1f71 |
File details
Details for the file oastodcat-2.0.0a4-py3-none-any.whl
.
File metadata
- Download URL: oastodcat-2.0.0a4-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/5.4.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08b560783e3d56c8d12d2d5fc9669f5e1bebd636a07ee9ae4094616fbf0bfc7a |
|
MD5 | fc42fc063b7cb8ab5985aefd0c2a95b2 |
|
BLAKE2b-256 | dcfa1e009b1fd65cdbebb09d95ff643f491611eb0501466ec01d997d567bd451 |