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
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
- 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 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().
Metadata
Release files for oastodcat 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oastodcat-2.0.2.tar.gz | 10.6 kB | Without provenance | Details for oastodcat-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oastodcat-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for oastodcat-2.0.2-py3-none-any.whl |
Total release size: 20.7 kB
Release files / oastodcat-2.0.2.tar.gz
| Download URL | oastodcat-2.0.2.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7e592f6bff4ef4ac3e9b6e23b1438dd0a3a3e26cc80fe56f273dadfe240c7a4
|
|
BLAKE2b-256 checksum How to use checksums |
85165f4c265b93c34cd975e257dc51e856bbbc9bd07f6eec506dfebbf05d675e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.8.10 Linux/5.15.0-1017-azure
|
Release files / oastodcat-2.0.2-py3-none-any.whl
| Download URL | oastodcat-2.0.2-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
75f714dd3148e05a2dc6aa50e05c4dba1118a0f3c8580e0e135b7ea9b6698370
|
|
BLAKE2b-256 checksum How to use checksums |
c2a24553c9fc8c86f96227fd34e972083f360c8e24830e892cae9b89851b8c43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.8.10 Linux/5.15.0-1017-azure
|
Security for oastodcat 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.