client
RDF4J client module.
Classes:
-
GraphStoreManager–An RDF4J Graph Store Protocol Client.
-
NamespaceListingResult–RDF4J namespace and prefix name result.
-
RDF4JClient–RDF4J client.
-
RDF4JNamespaceManager–A namespace manager for RDF4J repositories.
-
Repository–RDF4J repository client.
-
RepositoryListingResult–RDF4J repository listing result.
-
RepositoryManager–A client to manage server-level repository operations.
-
Transaction–An RDF4J transaction.
Attributes:
GraphStoreManager
GraphStoreManager(identifier: str, http_client: Client)
An RDF4J Graph Store Protocol Client.
Parameters:
-
(identifierstr) –The identifier of the repository.
-
(http_clientClient) –The httpx.Client instance.
Methods:
-
add–Add statements to the specified graph.
-
clear–Clear all statements in the specified graph.
-
get–Fetch all statements in the specified graph.
-
overwrite–Overwrite statements in the specified graph.
Attributes:
-
http_client– -
identifier–Repository identifier.
Source code in rdflib/contrib/rdf4j/client.py
add
add(graph_name: URIRef | str, data: str | bytes | BinaryIO | Graph)
Add statements to the specified graph.
Parameters:
-
(graph_nameURIRef | str) –The graph name of the graph.
For the default graph, use
DATASET_DEFAULT_GRAPH_ID. -
(datastr | bytes | BinaryIO | Graph) –The RDF data to add.
Source code in rdflib/contrib/rdf4j/client.py
clear
clear(graph_name: URIRef | str)
Clear all statements in the specified graph.
Parameters:
-
(graph_nameURIRef | str) –The graph name of the graph.
For the default graph, use
DATASET_DEFAULT_GRAPH_ID.
Source code in rdflib/contrib/rdf4j/client.py
get
get(graph_name: URIRef | str) -> Graph
Fetch all statements in the specified graph.
Parameters:
-
(graph_nameURIRef | str) –The graph name of the graph.
For the default graph, use
DATASET_DEFAULT_GRAPH_ID.
Returns:
Source code in rdflib/contrib/rdf4j/client.py
overwrite
overwrite(graph_name: URIRef | str, data: str | bytes | BinaryIO | Graph)
Overwrite statements in the specified graph.
Parameters:
-
(graph_nameURIRef | str) –The graph name of the graph.
For the default graph, use
DATASET_DEFAULT_GRAPH_ID. -
(datastr | bytes | BinaryIO | Graph) –The RDF data to overwrite with.
Source code in rdflib/contrib/rdf4j/client.py
NamespaceListingResult
dataclass
RDF4JClient
RDF4JClient(base_url: str, auth: tuple[str, str] | None = None, timeout: float = 30.0, **kwargs: Any)
RDF4J client.
Parameters:
-
(base_urlstr) –The base URL of the RDF4J server.
-
(authtuple[str, str] | None, default:None) –Authentication tuple (username, password).
-
(timeoutfloat, default:30.0) –Request timeout in seconds (default: 30.0).
-
(kwargsAny, default:{}) –Additional keyword arguments to pass to the httpx.Client.
Methods:
Attributes:
-
http_client– -
protocol(float) –The RDF4J REST API protocol version.
-
repositories(RepositoryManager) –Server-level repository management operations.
Source code in rdflib/contrib/rdf4j/client.py
protocol
property
The RDF4J REST API protocol version.
Returns:
-
float–The protocol version number.
repositories
property
repositories: RepositoryManager
Server-level repository management operations.
__enter__
__exit__
RDF4JNamespaceManager
RDF4JNamespaceManager(identifier: str, http_client: Client)
A namespace manager for RDF4J repositories.
Parameters:
-
(identifierstr) –The identifier of the repository.
-
(http_clientClient) –The httpx.Client instance.
Methods:
-
clear–Clear all namespace declarations in the repository.
-
get–Get the namespace URI for a given prefix.
-
list–List all namespace declarations in the repository.
-
remove–Remove the namespace declaration for a given prefix.
-
set–Set the namespace URI for a given prefix.
Attributes:
-
http_client– -
identifier–Repository identifier.
Source code in rdflib/contrib/rdf4j/client.py
clear
Clear all namespace declarations in the repository.
Source code in rdflib/contrib/rdf4j/client.py
get
get(prefix: str) -> str | None
Get the namespace URI for a given prefix.
Parameters:
-
(prefixstr) –The prefix to lookup.
Returns:
-
str | None–The namespace URI or
Noneif not found.
Source code in rdflib/contrib/rdf4j/client.py
list
list() -> list[NamespaceListingResult]
List all namespace declarations in the repository.
Returns:
-
list[NamespaceListingResult]–list[NamespaceListingResult]: List of namespace and prefix name results.
Raises:
-
RepositoryFormatError–If the response format is unrecognized.
Source code in rdflib/contrib/rdf4j/client.py
remove
remove(prefix: str)
Remove the namespace declaration for a given prefix.
Parameters:
-
(prefixstr) –The prefix to remove.
Source code in rdflib/contrib/rdf4j/client.py
set
Set the namespace URI for a given prefix.
Note
If the prefix was previously mapped to a different namespace, this will be overwritten.
Parameters:
-
(prefixstr) –The prefix to set.
-
(namespacestr) –The namespace URI to set.
Source code in rdflib/contrib/rdf4j/client.py
Repository
Repository(identifier: str, http_client: Client)
RDF4J repository client.
Parameters:
-
(identifierstr) –The identifier of the repository.
-
(http_clientClient) –The httpx.Client instance.
Methods:
-
delete–Deletes statements from the repository matching the filtering parameters.
-
get–Get RDF statements from the repository matching the filtering parameters.
-
graph_names–Get a list of all graph names in the repository.
-
health–Repository health check.
-
overwrite–Upload and overwrite statements in the repository.
-
query–Execute a SPARQL query against the repository.
-
size–The number of statements in the repository or in the specified graph name.
-
transaction–Create a new transaction for the repository.
-
update–Execute a SPARQL update operation on the repository.
-
upload–Upload and append statements to the repository.
Attributes:
-
graphs(GraphStoreManager) –Graph store manager for the repository.
-
http_client– -
identifier–Repository identifier.
-
namespaces(RDF4JNamespaceManager) –Namespace manager for the repository.
Source code in rdflib/contrib/rdf4j/client.py
delete
delete(subj: SubjectType = None, pred: PredicateType = None, obj: ObjectType = None, graph_name: URIRef | Iterable[URIRef] | str | None = None) -> None
Deletes statements from the repository matching the filtering parameters.
Note
The terms for subj, pred, obj or graph_name cannot be
BNodes.
Parameters:
-
(subjSubjectType, default:None) –Subject of the statement to filter by, or
Noneto match all. -
(predPredicateType, default:None) –Predicate of the statement to filter by, or
Noneto match all. -
(objObjectType, default:None) –Object of the statement to filter by, or
Noneto match all. -
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Nonequeries all graphs.To query just the default graph, use
DATASET_DEFAULT_GRAPH_ID.
Source code in rdflib/contrib/rdf4j/client.py
get
get(subj: SubjectType = None, pred: PredicateType = None, obj: ObjectType = None, graph_name: URIRef | Iterable[URIRef] | str | None = None, infer: bool = True, content_type: str | None = None) -> Graph | Dataset
Get RDF statements from the repository matching the filtering parameters.
Note
The terms for subj, pred, obj or graph_name cannot be
BNodes.
Parameters:
-
(subjSubjectType, default:None) –Subject of the statement to filter by, or
Noneto match all. -
(predPredicateType, default:None) –Predicate of the statement to filter by, or
Noneto match all. -
(objObjectType, default:None) –Object of the statement to filter by, or
Noneto match all. -
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Nonequeries all graphs.To query just the default graph, use
DATASET_DEFAULT_GRAPH_ID. -
(inferbool, default:True) –Specifies whether inferred statements should be included in the result.
-
(content_typestr | None, default:None) –
Returns:
Source code in rdflib/contrib/rdf4j/client.py
graph_names
graph_names() -> list[IdentifiedNode]
Get a list of all graph names in the repository.
Returns:
-
list[IdentifiedNode]–A list of graph names.
Raises:
-
RepositoryFormatError–Fails to parse the repository graph names.
Source code in rdflib/contrib/rdf4j/client.py
health
Repository health check.
Returns:
-
bool(bool) –True if the repository is healthy, otherwise an error is raised.
Raises:
-
RepositoryNotFoundError–If the repository is not found.
-
RepositoryNotHealthyError–If the repository is not healthy.
Source code in rdflib/contrib/rdf4j/client.py
overwrite
overwrite(data: str | bytes | BinaryIO | Graph | Dataset, graph_name: URIRef | Iterable[URIRef] | str | None = None, base_uri: str | None = None, content_type: str | None = None)
Upload and overwrite statements in the repository.
Parameters:
-
(datastr | bytes | BinaryIO | Graph | Dataset) –The RDF data to upload.
-
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Noneapplies to all graphs.To apply to just the default graph, use
DATASET_DEFAULT_GRAPH_ID. -
(base_uristr | None, default:None) –The base URI to resolve against for any relative URIs in the data.
-
(content_typestr | None, default:None) –The content type of the data. Defaults to
application/n-quadswhen the value isNone.
Source code in rdflib/contrib/rdf4j/client.py
query
Execute a SPARQL query against the repository.
Note
A POST request is used by default. If any keyword arguments are provided, a GET request is used instead, and the arguments are passed as query parameters.
Parameters:
-
(querystr) –The SPARQL query to execute.
-
–**kwargsAdditional keyword arguments to include as query parameters in the request. See RDF4J REST API - Execute SPARQL query for the list of supported query parameters.
Source code in rdflib/contrib/rdf4j/client.py
size
size(graph_name: URIRef | Iterable[URIRef] | str | None = None) -> int
The number of statements in the repository or in the specified graph name.
Parameters:
-
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Nonequeries all graphs.To query just the default graph, use
DATASET_DEFAULT_GRAPH_ID.
Returns:
-
int–The number of statements.
Raises:
-
RepositoryFormatError–Fails to parse the repository size.
Source code in rdflib/contrib/rdf4j/client.py
transaction
update
update(query: str)
Execute a SPARQL update operation on the repository.
Parameters:
-
(querystr) –The SPARQL update query to execute.
Source code in rdflib/contrib/rdf4j/client.py
upload
upload(data: str | bytes | BinaryIO | Graph | Dataset, base_uri: str | None = None, content_type: str | None = None)
Upload and append statements to the repository.
Parameters:
-
(datastr | bytes | BinaryIO | Graph | Dataset) –The RDF data to upload.
-
(base_uristr | None, default:None) –The base URI to resolve against for any relative URIs in the data.
-
(content_typestr | None, default:None) –The content type of the data. Defaults to
application/n-quadswhen the value isNone.
Source code in rdflib/contrib/rdf4j/client.py
RepositoryListingResult
dataclass
RepositoryListingResult(identifier: str, uri: str, readable: bool, writable: bool, title: str | None = None)
RDF4J repository listing result.
Parameters:
-
(identifierstr) –Repository identifier.
-
(uristr) –Repository URI.
-
(readablebool) –Whether the repository is readable by the client.
-
(writablebool) –Whether the repository is writable by the client.
-
(titlestr | None, default:None) –Repository title.
Attributes:
-
identifier(str) – -
readable(bool) – -
title(str | None) – -
uri(str) – -
writable(bool) –
RepositoryManager
RepositoryManager(http_client: Client)
A client to manage server-level repository operations.
Parameters:
-
(http_clientClient) –The httpx.Client instance.
Methods:
-
create–Create a new repository.
-
delete–Delete a repository.
-
get–Get a repository by ID.
-
list–List all available repositories.
Attributes:
Source code in rdflib/contrib/rdf4j/client.py
create
create(repository_id: str, data: str, content_type: str = 'text/turtle') -> Repository
Create a new repository.
Parameters:
-
(repository_idstr) –The identifier of the repository.
-
(datastr) –The repository configuration in RDF.
-
(content_typestr, default:'text/turtle') –The repository configuration content type.
Raises:
-
RepositoryAlreadyExistsError–If the repository already exists.
-
RepositoryNotHealthyError–If the repository is not healthy.
Source code in rdflib/contrib/rdf4j/client.py
delete
delete(repository_id: str) -> None
Delete a repository.
Parameters:
-
(repository_idstr) –The identifier of the repository.
Raises:
-
RepositoryNotFoundError–If the repository is not found.
-
RepositoryError–If the repository is not deleted successfully.
Source code in rdflib/contrib/rdf4j/client.py
get
get(repository_id: str) -> Repository
Get a repository by ID.
Note
This performs a health check before returning the repository object.
Parameters:
-
(repository_idstr) –The identifier of the repository.
Returns:
-
Repository(Repository) –The repository instance.
Raises:
-
RepositoryNotFoundError–If the repository is not found.
-
RepositoryNotHealthyError–If the repository is not healthy.
Source code in rdflib/contrib/rdf4j/client.py
list
list() -> list[RepositoryListingResult]
List all available repositories.
Returns:
-
list[RepositoryListingResult]–list[RepositoryListingResult]: List of repository results.
Raises:
-
RepositoryFormatError–If the response format is unrecognized.
Source code in rdflib/contrib/rdf4j/client.py
Transaction
Transaction(repo: Repository)
An RDF4J transaction.
Parameters:
-
(repoRepository) –The repository instance.
Methods:
-
__enter__– -
__exit__– -
commit–Commit the transaction.
-
delete–Delete statements from the repository.
-
get–Get RDF statements from the repository matching the filtering parameters.
-
open–Opens a transaction.
-
ping–Ping the transaction.
-
query–Execute a SPARQL query against the repository.
-
rollback–Roll back the transaction.
-
size–The number of statements in the repository or in the specified graph name.
-
update–Execute a SPARQL update operation on the repository.
-
upload–Upload and append statements to the repository.
Attributes:
-
is_closed(bool) –Whether the transaction is closed.
-
repo–The repository instance.
-
url–The transaction URL.
Source code in rdflib/contrib/rdf4j/client.py
__enter__
__exit__
commit
Commit the transaction.
Raises:
-
TransactionCommitError–If the transaction commit fails.
-
TransactionClosedError–If the transaction is closed.
Source code in rdflib/contrib/rdf4j/client.py
delete
delete(data: str | bytes | BinaryIO | Graph | Dataset, base_uri: str | None = None, content_type: str | None = None) -> None
Delete statements from the repository.
Note
This function operates differently to
Repository.delete
as it does not use filter parameters. Instead, it expects a data payload.
See the notes from
graphdb.js#Deleting
for more information.
Parameters:
-
(datastr | bytes | BinaryIO | Graph | Dataset) –The RDF data to upload.
-
(base_uristr | None, default:None) –The base URI to resolve against for any relative URIs in the data.
-
(content_typestr | None, default:None) –The content type of the data. Defaults to
application/n-quadswhen the value isNone.
Source code in rdflib/contrib/rdf4j/client.py
get
get(subj: SubjectType = None, pred: PredicateType = None, obj: ObjectType = None, graph_name: URIRef | Iterable[URIRef] | str | None = None, infer: bool = True, content_type: str | None = None) -> Graph | Dataset
Get RDF statements from the repository matching the filtering parameters.
Note
The terms for subj, pred, obj or graph_name cannot be
BNodes.
Parameters:
-
(subjSubjectType, default:None) –Subject of the statement to filter by, or
Noneto match all. -
(predPredicateType, default:None) –Predicate of the statement to filter by, or
Noneto match all. -
(objObjectType, default:None) –Object of the statement to filter by, or
Noneto match all. -
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Nonequeries all graphs.To query just the default graph, use
DATASET_DEFAULT_GRAPH_ID. -
(inferbool, default:True) –Specifies whether inferred statements should be included in the result.
-
(content_typestr | None, default:None) –
Returns:
Source code in rdflib/contrib/rdf4j/client.py
open
ping
Ping the transaction.
Raises:
-
RepositoryTransactionPingError–If the transaction ping fails.
-
TransactionClosedError–If the transaction is closed.
Source code in rdflib/contrib/rdf4j/client.py
query
Execute a SPARQL query against the repository.
Parameters:
-
(querystr) –The SPARQL query to execute.
-
–**kwargsAdditional keyword arguments to include as query parameters in the request. See RDF4J REST API - Execute SPARQL query for the list of supported query parameters.
Source code in rdflib/contrib/rdf4j/client.py
rollback
Roll back the transaction.
Source code in rdflib/contrib/rdf4j/client.py
size
size(graph_name: URIRef | Iterable[URIRef] | str | None = None)
The number of statements in the repository or in the specified graph name.
Parameters:
-
(graph_nameURIRef | Iterable[URIRef] | str | None, default:None) –Graph name(s) to restrict to.
The default value
Nonequeries all graphs.To query just the default graph, use
DATASET_DEFAULT_GRAPH_ID.
Returns:
-
–
The number of statements.
Raises:
-
RepositoryFormatError–Fails to parse the repository size.
Source code in rdflib/contrib/rdf4j/client.py
update
Execute a SPARQL update operation on the repository.
Parameters:
-
(querystr) –The SPARQL update query to execute.
-
–**kwargsAdditional keyword arguments to include as query parameters See RDF4J REST API - Execute a transaction action for the list of supported query parameters.
Source code in rdflib/contrib/rdf4j/client.py
upload
upload(data: str | bytes | BinaryIO | Graph | Dataset, base_uri: str | None = None, content_type: str | None = None)
Upload and append statements to the repository.
Parameters:
-
(datastr | bytes | BinaryIO | Graph | Dataset) –The RDF data to upload.
-
(base_uristr | None, default:None) –The base URI to resolve against for any relative URIs in the data.
-
(content_typestr | None, default:None) –The content type of the data. Defaults to
application/n-quadswhen the value isNone.