Graph Store Protocol¶
kurra.db.gsp
¶
SPARQL Graph Store Protocol functions.
These are knonw to work well with Jena Fuseki and GraphDB but may need testing for other RDF Database implementations
due to differences in repository/dataset endpoints some of them use. See
utils.make_system_specific_sparql_endpoint()
for some endpoint difference handling.
exists(sparql_endpoint: str, graph_iri: str, http_client: httpx.Client | None = None) -> bool
¶
Returns True if a graph with the given graph_iri exists at the SPARQL Endpoint or else False
Source code in kurra/db/gsp.py
get(sparql_endpoint: str, graph_iri: str = None, accept_type: str = 'text/turtle', return_format: LiteralType['original', 'python'] = 'python', http_client: httpx.Client | None = None) -> Union[Graph, int]
¶
Graph Store Protocol's HTTP GET: https://www.w3.org/TR/sparql12-graph-store-protocol/#http-get
Returns the content of the graph identified by graph_id in the target SPARQL Endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use |
required |
graph_iri
|
str
|
The IRI of the graph to retrieve |
None
|
accept_type
|
str
|
The RDF format to request from the server and to return if return_format is set to 'original' |
'text/turtle'
|
return_format
|
Literal['original', 'python']
|
The return format to use, 'python' - RDFLib's Graph - or 'original' - an RDF string value in the format of accept_type |
'python'
|
http_client
|
Client | None
|
An HTTP client to use. Created internally if not supplied |
None
|
Returns:
| Type | Description |
|---|---|
Union[Graph, int]
|
An RDF result as either an RDFLib Graph object or a string object containing RDF in the accept_type |
Union[Graph, int]
|
format. If a graph, the graph identifier will be the graph_iri or a Blank Node if None/default |
Source code in kurra/db/gsp.py
put(sparql_endpoint: str, file_or_str_or_graph: Union[Path, str, Graph], graph_iri: str = None, content_type='text/turtle', http_client: httpx.Client | None = None) -> Union[Graph, int]
¶
Graph Store Protocol's HTTP PUT: https://www.w3.org/TR/sparql12-graph-store-protocol/#http-put
Inserts the RDF content supplied into a graph identified by graph_id or the default graph.
Will replace existing content.
Source code in kurra/db/gsp.py
post(sparql_endpoint: str, file_or_str_or_graph: Union[Path, str, Graph], graph_iri: str = None, content_type='text/turtle', http_client: httpx.Client | None = None) -> Union[Graph, int]
¶
Graph Store Protocol's HTTP POST: https://www.w3.org/TR/sparql12-graph-store-protocol/#http-post
Inserts the RDF content supplied into a graph identified by graph_id or the default graph.
Will add to existing content.
Source code in kurra/db/gsp.py
delete(sparql_endpoint: str, graph_iri: str = None, http_client: httpx.Client | None = None) -> Union[Graph, int]
¶
Graph Store Protocol's HTTP DELETE: https://www.w3.org/TR/sparql12-graph-store-protocol/#http-delete
Deletes the graph identified by graph_id or the default graph.
Source code in kurra/db/gsp.py
clear(sparql_endpoint: str, graph_iri: str, http_client: httpx.Client | None = None)
¶
Clears - remove all triples from - a graph identified by graph_iri. Special values for graph_iri are 'default' - clears the default graph - and 'all' which clears all graphs.
This function operates much like SPARQL Update's Clear function - https://www.w3.org/TR/sparql12-update/#clear - but uses GSP Delete under the hood and handles the 'default' and 'all' special cases.
Source code in kurra/db/gsp.py
upload(sparql_endpoint: str, file_or_str_or_graph: Union[Path, str, Graph], graph_id: str | None = None, append: bool = False, content_type: str = 'text/turtle', http_client: httpx.Client | None = None) -> Union[bool, int]
¶
This function uploads a file to a SPARQL Endpoint using the Graph Store Protocol.
It will upload it into a graph identified by graph_id (an IRI or Blank Node). If no graph_id is given, it will be uploaded into the default graph.
By default, it will replace all content in the Named Graph or default graph. If append is set to True, it will add it to existing content in the graph_id Named Graph.
This function is an alias of put() (append=False) and post() (append=True).