Skip to main content

A library for transforming an openAPI file to one or more dcat:DataService

Project description

oastodcat

Tests codecov PyPI Read the Docs

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

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)

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 url to description
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

% pipx install poetry==1.0.5
% pipx install nox==2019.11.9
% pipx inject nox nox-poetry

Install dependencies

```Shell
% git clone https://github.com/Informasjonsforvaltning/oastodcat.git
% cd oastodcat
% pyenv install 3.8.6
% pyenv install 3.9.0
% pyenv install 3.10.4
% 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oastodcat-2.0.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

oastodcat-2.0.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file oastodcat-2.0.1.tar.gz.

File metadata

  • Download URL: oastodcat-2.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.10 Linux/5.15.0-1014-azure

File hashes

Hashes for oastodcat-2.0.1.tar.gz
Algorithm Hash digest
SHA256 84fa2e3694237e96abf1f9648f7c0ccd29a1547ea2e6e52ec83bebece08f67db
MD5 af12311ce8db57508d1c0fab876ad8a5
BLAKE2b-256 c5429d0c50d0bc34e5e7f45119aba02a27eafd7548b9621b067dca5d1e4bc4d3

See more details on using hashes here.

File details

Details for the file oastodcat-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: oastodcat-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.10 Linux/5.15.0-1014-azure

File hashes

Hashes for oastodcat-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24df59e42b675fc4a264d34a8057b368c33c832d79a6ab65bb204fe2a0dae386
MD5 7d63d58b6e999522303f35b78116a9d4
BLAKE2b-256 797e246215426dd1d73f9562d2d22f64f7ed918613dc47122a629a752b94f05a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page