Graph Store Protocol¶
kurra.db.gsp ¶
SPARQL Graph Store Protocol functions.
These are known 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 ¶
Check whether a graph exists at a 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 check. If None, the default graph is checked. |
required |
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the graph exists, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in kurra/db/gsp.py
get ¶
get(sparql_endpoint: str, graph_iri: str = None, accept_type: str = 'text/turtle', return_format: Literal['original', 'python'] = 'python', http_client: Client | None = None) -> Union[Graph, int]
Graph Store Protocol's HTTP GET.
Returns the content of the graph identified by graph_iri 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']
|
|
'python'
|
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
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 |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in kurra/db/gsp.py
put ¶
put(sparql_endpoint: str, file_or_str_or_graph: Union[Path, str, Graph], graph_iri: str = None, content_type: str = 'text/turtle', http_client: Client | None = None) -> Union[Graph, int]
Graph Store Protocol's HTTP PUT.
Inserts the RDF content supplied into a graph identified by graph_iri or the default graph, replacing existing content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use. |
required |
file_or_str_or_graph
|
Union[Path, str, Graph]
|
The RDF content to insert as a file path, an RDF string, or a Graph. |
required |
graph_iri
|
str
|
The IRI of the graph to insert into. If None, the default graph is targeted. |
None
|
content_type
|
str
|
The RDF media type to serialize the content as. |
'text/turtle'
|
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Graph, int]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in kurra/db/gsp.py
post ¶
post(sparql_endpoint: str, file_or_str_or_graph: Union[Path, str, Graph], graph_iri: str = None, content_type: str = 'text/turtle', http_client: Client | None = None) -> Union[Graph, int]
Graph Store Protocol's HTTP POST.
Inserts the RDF content supplied into a graph identified by graph_iri or the default graph, adding to existing content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use. |
required |
file_or_str_or_graph
|
Union[Path, str, Graph]
|
The RDF content to insert as a file path, an RDF string, or a Graph. |
required |
graph_iri
|
str
|
The IRI of the graph to insert into. If None, the default graph is targeted. |
None
|
content_type
|
str
|
The RDF media type to serialize the content as. |
'text/turtle'
|
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Graph, int]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in kurra/db/gsp.py
delete ¶
delete(sparql_endpoint: str, graph_iri: str = None, http_client: Client | None = None) -> Union[Graph, int]
Graph Store Protocol's HTTP DELETE.
Deletes the graph identified by graph_iri, or the default graph if not given.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use. |
required |
graph_iri
|
str
|
The IRI of the graph to delete. If None, the default graph is targeted. |
None
|
http_client
|
Client | None
|
An HTTP client to use. Created internally if not supplied. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Graph, int]
|
A tuple of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in kurra/db/gsp.py
clear ¶
Clear/Remove all triples from a graph identified by graph_iri.
Special values for graph_iri are "default" (clears the default graph) and "all" (clears every graph). Operates much like SPARQL Update's Clear function, but uses GSP DELETE under the hood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use. |
required |
graph_iri
|
str
|
The IRI of the graph to clear, or "default"/"all". |
required |
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Graph, int]
|
A tuple of |
Source code in kurra/db/gsp.py
upload ¶
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: Client | None = None) -> Union[bool, int]
Upload a file, string, or Graph to a SPARQL endpoint using the Graph Store Protocol.
Uploads into the graph identified by graph_id (an IRI), or the default graph if not given. By default, replaces all content in the target graph; if append is True, adds to existing content instead. This is an alias for put (append=False) and post (append=True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql_endpoint
|
str
|
The SPARQL Endpoint URL to use. |
required |
file_or_str_or_graph
|
Union[Path, str, Graph]
|
The RDF content to upload as a file path, an RDF string, or a Graph. |
required |
graph_id
|
str | None
|
The IRI of the graph to upload into. If None, the default graph is targeted. |
None
|
append
|
bool
|
If True, add to existing content (via |
False
|
content_type
|
str
|
The RDF media type to serialize the content as. |
'text/turtle'
|
http_client
|
Client | None
|
An optional HTTPX client to contain credentials if needed. A new one is created if not given. |
None
|
Returns:
| Type | Description |
|---|---|
Union[bool, int]
|
A tuple of |