https://github.com/acdh-oeaw/rdfproxy
Python library for building REST APIs on top of SPARQL endpoints
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.7%) to scientific vocabulary
Keywords
Repository
Python library for building REST APIs on top of SPARQL endpoints
Basic Info
- Host: GitHub
- Owner: acdh-oeaw
- License: gpl-3.0
- Language: Python
- Default Branch: main
- Homepage: https://acdh-oeaw.github.io/rdfproxy/
- Size: 790 KB
Statistics
- Stars: 7
- Watchers: 6
- Forks: 0
- Open Issues: 31
- Releases: 11
Topics
Metadata Files
README.md
RDFProxy
RDFProxy is a Python library for building REST APIs on top of SPARQL endpoints.
SPARQLModelAdapter
The rdfproxy.SPARQLModelAdapter class allows to run a SPARQL query against an endpoint and map the query result set to a potentially nested Pydantic model.
The following example query
sparql
select *
where {
values (?gnd ?authorName ?educatedAt ?workName ?work ?viaf) {
("119359464" 'Schindel' UNDEF 'Gebürtig' <http://www.wikidata.org/entity/Q1497409> UNDEF)
("115612815" 'Geiger' 'University of Vienna' 'Der alte König in seinem Exil' <http://www.wikidata.org/entity/Q15805238> "299260555")
("115612815" 'Geiger' 'University of Vienna' 'Der alte König in seinem Exil' <http://www.wikidata.org/entity/Q15805238> "6762154387354230970008")
("115612815" 'Geiger' 'University of Vienna' 'Unter der Drachenwand' <http://www.wikidata.org/entity/Q58038819> "2277151717053313900002")
("1136992030" 'Edelbauer' 'University of Vienna' 'Das flüssige Land' <http://www.wikidata.org/entity/Q100266054> UNDEF)
("1136992030" 'Edelbauer' 'University of Applied Arts Vienna' 'Das flüssige Land' <http://www.wikidata.org/entity/Q100266054> UNDEF)
}
}
retrieves the result set:
| gnd | nameLabel | educatedatLabel | workname | work | viaf | |--------------|-----------|-----------------------------------|-------------------------------|-------------------------------------------|--------------------------| | "119359464" | Schindel | | Gebürtig | http://www.wikidata.org/entity/Q1497409 | | | "115612815" | Geiger | University of Vienna | Der alte König in seinem Exil | http://www.wikidata.org/entity/Q15805238 | "299260555" | | "115612815" | Geiger | University of Vienna | Der alte König in seinem Exil | http://www.wikidata.org/entity/Q15805238 | "6762154387354230970008" | | "115612815" | Geiger | University of Vienna | Unter der Drachenwand | http://www.wikidata.org/entity/Q58038819 | "2277151717053313900002" | | "1136992030" | Edelbauer | University of Vienna | Das flüssige Land | http://www.wikidata.org/entity/Q100266054 | | | "1136992030" | Edelbauer | University of Applied Arts Vienna | Das flüssige Land | http://www.wikidata.org/entity/Q100266054 | |
The result set can be mapped to a nested Pydantic model like so:
```python from typing import Annotated
from fastapi import FastAPI, Query from pydantic import BaseModel from rdfproxy import ConfigDict, Page, QueryParameters, SPARQLBinding, SPARQLModelAdapter
class Work(BaseModel): modelconfig = ConfigDict(groupby="name")
name: Annotated[str, SPARQLBinding("workName")]
viafs: Annotated[list[str], SPARQLBinding("viaf")]
class Author(BaseModel): modelconfig = ConfigDict(groupby="surname")
gnd: str
surname: Annotated[str, SPARQLBinding("authorName")]
works: list[Work]
education: Annotated[list[str], SPARQLBinding("educatedAt")]
adapter = SPARQLModelAdapter( target="https://query.wikidata.org/bigdata/namespace/wdq/sparql", query=query, model=Author, ) ```
Note that grouping and aggregation of scalar values and nested models is supported by specifying a group_by entry in the rdfproxy.ConfigDict and indicating an aggregation target with a list-annotated field in the model.
The SPARQLModelAdapter.get_page method runs the query and constructs a Page object which can then be served over a FastAPI route:
```python app = FastAPI()
@app.get("/") def baseroute(queryparameters: Annotated[QueryParameters, Query()]) -> Page[Author]: return adapter.getpage(queryparameters) ```
This results in the following JSON output:
```json { "items":[ { "gnd":"119359464", "surname":"Schindel", "works":[ { "name":"Gebürtig", "viafs":[
]
}
],
"education":[
]
},
{
"gnd":"115612815",
"surname":"Geiger",
"works":[
{
"name":"Der alte König in seinem Exil",
"viafs":[
"299260555",
"6762154387354230970008"
]
},
{
"name":"Unter der Drachenwand",
"viafs":[
"2277151717053313900002"
]
}
],
"education":[
"University of Vienna"
]
},
{
"gnd":"1136992030",
"surname":"Edelbauer",
"works":[
{
"name":"Das flüssige Land",
"viafs":[
]
}
],
"education":[
"University of Vienna",
"University of Applied Arts Vienna"
]
}
], "page":1, "size":100, "total":3, "pages":1 } ```
Owner
- Name: Austrian Centre for Digital Humanities & Cultural Heritage
- Login: acdh-oeaw
- Kind: organization
- Email: acdh@oeaw.ac.at
- Location: Vienna, Austria
- Website: https://www.oeaw.ac.at/acdh
- Repositories: 476
- Profile: https://github.com/acdh-oeaw
GitHub Events
Total
- Create event: 113
- Release event: 10
- Issues event: 171
- Watch event: 6
- Delete event: 89
- Member event: 1
- Issue comment event: 234
- Push event: 475
- Pull request review comment event: 13
- Pull request review event: 68
- Pull request event: 196
Last Year
- Create event: 113
- Release event: 10
- Issues event: 171
- Watch event: 6
- Delete event: 89
- Member event: 1
- Issue comment event: 234
- Push event: 475
- Pull request review comment event: 13
- Pull request review event: 68
- Pull request event: 196
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 119
- Total pull requests: 206
- Average time to close issues: 27 days
- Average time to close pull requests: 10 days
- Total issue authors: 5
- Total pull request authors: 4
- Average comments per issue: 1.37
- Average comments per pull request: 0.48
- Merged pull requests: 126
- Bot issues: 1
- Bot pull requests: 60
Past Year
- Issues: 94
- Pull requests: 160
- Average time to close issues: 28 days
- Average time to close pull requests: 11 days
- Issue authors: 5
- Pull request authors: 3
- Average comments per issue: 1.44
- Average comments per pull request: 0.36
- Merged pull requests: 101
- Bot issues: 1
- Bot pull requests: 47
Top Authors
Issue Authors
- lu-pl (99)
- kevinstadler (14)
- b1rger (12)
- sennierer (1)
Pull Request Authors
- lu-pl (200)
- dependabot[bot] (84)
- github-actions[bot] (19)
- b1rger (4)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 299 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 9
- Total maintainers: 1
pypi.org: rdfproxy
- Documentation: https://rdfproxy.readthedocs.io/
- License: gpl-3.0
-
Latest release: 0.9.0
published 6 months ago
Rankings
Maintainers (1)
Dependencies
- googleapis/release-please-action v3 composite
- annotated-types 0.7.0
- click 8.1.7
- colorama 0.4.6
- deptry 0.17.0
- isodate 0.6.1
- pydantic 2.8.2
- pydantic-core 2.20.1
- pyparsing 3.1.2
- rdflib 7.0.0
- ruff 0.5.4
- six 1.16.0
- sparqlwrapper 2.0.0
- toolz 0.12.1
- typing-extensions 4.12.2
- deptry ^0.17.0 develop
- ruff ^0.5.4 develop
- pydantic ^2.8.2
- python ^3.12
- sparqlwrapper ^2.0.0
- toolz ^0.12.1
- actions/checkout v4 composite
- actions/setup-python v4 composite
- coverallsapp/github-action v2.2.3 composite