RDF-FastAPI-Utils
This is a small utils library for providing access to data in a triplestore via a FastAPI Rest endpoint. Currently it contains only those classes used to convert a Json resulting from a SPARQL query into a given pydantic model.
Currently it contains two classes:
models.FieldConfigurationRDFto add additional information for processing RDF data to the fields in a pydantic model- and
models.RDFUtilsModelBaseClassas a pydantic base class to inherit from for adding SPARQL Json to a pydantic model.
Minimal example
this is taken from the tests
models.py:
from pydantic import Field
from rdf_fastapi_utils.models import FieldConfigurationRDF, RDFUtilsModelBaseClass
class TCPaginatedResponse(RDFUtilsModelBaseClass):
count: int = Field(..., rdfconfig=FieldConfigurationRDF(path="count"))
results: list[Union["TCPersonFull", "TCPlaceFull"]] = Field(
...,
rdfconfig=FieldConfigurationRDF(path="results", serialization_class_callback=lambda field, item: TCPersonFull),
)
class TCPersonFull(RDFUtilsModelBaseClass):
id: str = Field(..., rdfconfig=FieldConfigurationRDF(anchor=True, path="person"))
name: str = Field(..., rdfconfig=FieldConfigurationRDF(path="entityLabel"))
events: list["TCEventFull"] = None
class TCPlaceFull(RDFUtilsModelBaseClass):
id: str = Field(..., rdfconfig=FieldConfigurationRDF(anchor=True, path="person"))
name: str = Field(..., rdfconfig=FieldConfigurationRDF(path="entityLabel"))
events: list["TCEventFull"] = None
class TCEventFull(RDFUtilsModelBaseClass):
id: str = Field(..., rdfconfig=FieldConfigurationRDF(anchor=True, path="event"))
label: str = Field(..., rdfconfig=FieldConfigurationRDF(path="eventLabel"))
TCPaginatedResponse.update_forward_refs()
TCPersonFull.update_forward_refs()
TCEventFull.update_forward_refs()
test_data.json
{
"page": 1,
"count": 1,
"pages": 1,
"results": [
{
"count": 1,
"person": "http://www.intavia.eu/apis/personproxy/27118",
"entityTypeLabel": "person",
"entityLabel": "Tesla, Nikola",
"linkedIds": "https://apis-edits.acdh-dev.oeaw.ac.at/entity/27118/",
"role": "http://www.intavia.eu/apis/deceased_person/27118",
"event": "http://www.intavia.eu/apis/deathevent/27118",
"evPlace": "http://www.intavia.eu/apis/place/25209",
"evPlaceLatLong": "Point ( -74.00597 +40.71427 )",
"evPlaceLabel": "New York City",
"eventLabel": "Death of Nikola Tesla",
"end": "1943-01-07 23:59:59+00:00"
},
{
"count": 1,
"person": "http://www.intavia.eu/apis/personproxy/27118",
"entityTypeLabel": "person",
"entityLabel": "Tesla, Nikola",
"linkedIds": "https://apis.acdh.oeaw.ac.at/entity/27118",
"role": "http://www.intavia.eu/apis/deceased_person/27118",
"event": "http://www.intavia.eu/apis/deathevent/27118",
"evPlace": "http://www.intavia.eu/apis/place/25209",
"evPlaceLatLong": "Point ( -74.00597 +40.71427 )",
"evPlaceLabel": "New York City",
"eventLabel": "Death of Nikola Tesla",
"end": "1943-01-07 23:59:59+00:00"
},
{
"count": 1,
"person": "http://www.intavia.eu/apis/personproxy/27118",
"entityTypeLabel": "person",
"entityLabel": "Tesla, Nikola",
"linkedIds": "https://apis-edits.acdh-dev.oeaw.ac.at/entity/27118/",
"role": "http://www.intavia.eu/apis/personplace/eventrole/155790",
"event": "http://www.intavia.eu/apis/event/personplace/155790",
"evPlace": "http://www.intavia.eu/apis/place/129965",
"evPlaceLatLong": "Point ( +15.31806 +44.56389 )",
"evPlaceLabel": "Smiljan",
"roleLabel": "ausgebildet in",
"eventLabel": "Tesla, Nikola ausgebildet in Smiljan",
"start": "1862-01-01 00:00:00+00:00",
"end": "1866-12-31 23:59:59+00:00"
},
{
"count": 1,
"person": "http://www.intavia.eu/apis/personproxy/27118",
"entityTypeLabel": "person",
"entityLabel": "Tesla, Nikola",
"linkedIds": "https://apis.acdh.oeaw.ac.at/entity/27118",
"role": "http://www.intavia.eu/apis/personplace/eventrole/155790",
"event": "http://www.intavia.eu/apis/event/personplace/155790",
"evPlace": "http://www.intavia.eu/apis/place/129965",
"evPlaceLatLong": "Point ( +15.31806 +44.56389 )",
"evPlaceLabel": "Smiljan",
"roleLabel": "ausgebildet in",
"eventLabel": "Tesla, Nikola ausgebildet in Smiljan",
"start": "1862-01-01 00:00:00+00:00",
"end": "1866-12-31 23:59:59+00:00"
}
]
}
Running the following with the above files in place will result in a correctly nested python object:
import json
from .models import TCPaginatedResponse
with open("test_data.json") as inp:
data = json.load(inp)
res = TCPaginatedResponse(**data)
print(res)
Metadata
Release files for rdf-fastapi-utils 0.1.3
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 |
|---|---|---|---|---|
| rdf_fastapi_utils-0.1.3.tar.gz | 8.4 kB | Without provenance | Details for rdf_fastapi_utils-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rdf_fastapi_utils-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for rdf_fastapi_utils-0.1.3-py3-none-any.whl |
Total release size: 17.1 kB
Release files / rdf_fastapi_utils-0.1.3.tar.gz
| Download URL | rdf_fastapi_utils-0.1.3.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
473605db85de88c188bb86843270063dd79447c37f029e57cff0cd692f89f931
|
|
BLAKE2b-256 checksum How to use checksums |
38908f3b54d984f2649dbf385ddfecd3728804beff4fcf25095bae78036bb16e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.8 Linux/5.19.13-300.fc37.x86_64
|
Release files / rdf_fastapi_utils-0.1.3-py3-none-any.whl
| Download URL | rdf_fastapi_utils-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de7c308cb8f118dd1287b0a14ac418b81f8066cf293d3f9ff6611c648d95953d
|
|
BLAKE2b-256 checksum How to use checksums |
7e89a199a3f8acb149073076b7b2ca6fd0610531e84e0540c84ff5efcbbd4de1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.8 Linux/5.19.13-300.fc37.x86_64
|
Security for rdf-fastapi-utils 0.1.3
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.