rdf4j_python¶
RDF4J Python is a Python library for interacting with RDF4J repositories.
- class rdf4j_python.AsyncNamedGraph(client: AsyncApiClient, repository_id: str, graph_uri: str)[source]¶
Bases:
objectAsynchronous interface for operations on a specific RDF4J named graph.
- async add(statements: Iterable[Quad] | Iterable[Triple])[source]¶
Adds RDF statements to this named graph.
- async clear()[source]¶
Deletes all statements from this named graph.
- Raises:
httpx.HTTPStatusError – If the request fails.
- async get() QuadParser[source]¶
Fetches all RDF statements from this named graph.
- Returns:
RDF data serialized in the requested format.
- Return type:
QuadResultSet
- Raises:
httpx.HTTPStatusError – If the request fails.
- property iri: NamedNode¶
Returns the IRI of the named graph.
- Returns:
The graph IRI.
- Return type:
str
- class rdf4j_python.AsyncRdf4JRepository(client: AsyncApiClient, repository_id: str)[source]¶
Bases:
objectAsynchronous interface for interacting with an RDF4J repository.
- async add_statement(subject: NamedNode | BlankNode | Triple, predicate: NamedNode, object: NamedNode | BlankNode | Literal, context: NamedNode | BlankNode | DefaultGraph | None = None) None[source]¶
Adds a single RDF statement to the repository.
- Parameters:
subject (Node) – The subject of the triple.
predicate (Node) – The predicate of the triple.
object (Node) – The object of the triple.
context (IdentifiedNode) – The context (named graph).
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If addition fails.
- async add_statements(statements: Iterable[Quad] | Iterable[Triple]) None[source]¶
Adds a list of RDF statements to the repository.
- Parameters:
statements (Iterable[Quad] | Iterable[Triple]) – A list of RDF statements.
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If addition fails.
- async clear_all_namespaces() None[source]¶
Removes all namespaces from the repository.
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If clearing fails.
- async delete_namespace(prefix: str) None[source]¶
Deletes a namespace by prefix.
- Parameters:
prefix (str) – The namespace prefix.
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If deletion fails.
- async delete_statements(subject: NamedNode | BlankNode | Triple | None = None, predicate: NamedNode | None = None, object_: NamedNode | BlankNode | Literal | None = None, contexts: list[NamedNode | BlankNode | DefaultGraph | None] | None = None) None[source]¶
Deletes statements from the repository matching the given pattern.
- Parameters:
subject (Optional[Subject]) – Filter by subject (N-Triples encoded).
predicate (Optional[Predicate]) – Filter by predicate (N-Triples encoded).
object (Optional[Object]) – Filter by object (N-Triples encoded).
contexts (Optional[list[Context]]) – One or more specific contexts to restrict deletion to. Use ‘null’ as a string to delete context-less statements.
- Raises:
RepositoryNotFoundException – If the repository does not exist.
RepositoryUpdateException – If the deletion fails.
- async get_named_graph(graph: str) AsyncNamedGraph[source]¶
Retrieves a named graph in the repository.
- Returns:
A named graph object.
- Return type:
- async get_namespace(prefix: str) Namespace[source]¶
Gets a namespace by its prefix.
- Parameters:
prefix (str) – The namespace prefix.
- Returns:
The namespace object.
- Return type:
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
NamespaceException – If retrieval fails.
- async get_namespaces() list[Namespace][source]¶
Retrieves all namespaces in the repository.
- Returns:
A list of namespace objects.
- Return type:
list[Namespace]
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
- async get_sparql_wrapper() SPARQLWrapper[source]¶
Returns the SPARQLWrapper for the repository.
- Returns:
The SPARQLWrapper for the repository.
- Return type:
SPARQLWrapper
- async get_statements(subject: NamedNode | BlankNode | Triple | None = None, predicate: NamedNode | None = None, object_: NamedNode | BlankNode | Literal | None = None, contexts: list[NamedNode | BlankNode | DefaultGraph | None] | None = None, infer: bool = True) QuadParser[source]¶
Retrieves statements matching the given pattern.
- Parameters:
subject (Optional[Subject]) – Filter by subject.
predicate (Optional[Predicate]) – Filter by predicate.
object (Optional[Object]) – Filter by object.
contexts (Optional[list[Context]]) – Filter by context (named graph).
- Returns:
QuadResultSet of matching RDF statements.
- Return type:
QuadResultSet
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
- async query(sparql_query: str, infer: bool = True) QuerySolutions | QueryBoolean | QueryTriples[source]¶
Executes a SPARQL query (SELECT, ASK, CONSTRUCT, or DESCRIBE).
- Parameters:
sparql_query (str) – The SPARQL query string.
infer (bool) – Whether to include inferred statements. Defaults to True.
- Returns:
Parsed query results.
- Return type:
og.QuerySolutions | og.QueryBoolean | og.QueryTriples
Note
This method correctly handles queries with PREFIX declarations, BASE URIs, and comments before the query keyword.
- async replace_statements(statements: Iterable[Quad] | Iterable[Triple], contexts: Iterable[NamedNode | BlankNode | DefaultGraph | None] | None = None, base_uri: str | None = None) None[source]¶
Replaces all repository statements with the given RDF data.
- Parameters:
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If the operation fails.
- async set_namespace(prefix: str, namespace: NamedNode)[source]¶
Sets a namespace prefix.
- Parameters:
prefix (str) – The namespace prefix.
namespace (IRI) – The namespace URI.
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
NamespaceException – If the request fails.
- async size() int[source]¶
Gets the number of statements in the repository.
- Returns:
The total number of RDF statements.
- Return type:
int
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
RepositoryInternalException – If retrieval fails.
- transaction(isolation_level: IsolationLevel | None = None) AsyncTransaction[source]¶
Creates a new transaction for this repository.
Transactions allow grouping multiple operations (add, delete, update) into a single atomic unit. Either all operations succeed (commit) or none of them take effect (rollback).
- Parameters:
isolation_level – Optional isolation level for the transaction. Supported levels depend on the RDF4J store implementation. Common levels include SNAPSHOT, SERIALIZABLE, READ_COMMITTED.
- Returns:
A transaction context manager.
- Return type:
Example
```python # Using as context manager (recommended) async with repo.transaction() as txn:
await txn.add_statements([quad1, quad2]) await txn.delete_statements([quad3]) # Auto-commits on success, auto-rollbacks on exception
# With isolation level async with repo.transaction(IsolationLevel.SERIALIZABLE) as txn:
await txn.add_statements([quad1])
- async update(sparql_update_query: str, content_type: Rdf4jContentType) None[source]¶
Executes a SPARQL UPDATE command.
- Parameters:
sparql_update (str) – The SPARQL update string.
- Raises:
RepositoryNotFoundException – If the repository doesn’t exist.
httpx.HTTPStatusError – If the update fails.
- async upload_file(file_path: str | Path, rdf_format: RdfFormat | None = None, context: NamedNode | BlankNode | DefaultGraph | None = None, base_uri: str | None = None) None[source]¶
Uploads an RDF file to the repository.
This method reads an RDF file from disk and uploads its contents to the repository. The file can be in various RDF formats such as Turtle, N-Triples, N-Quads, RDF/XML, JSON-LD, TriG, or N3.
- Parameters:
file_path (Union[str, Path]) – Path to the RDF file to upload.
rdf_format (Optional[og.RdfFormat]) – The RDF format of the file. If None, the format is automatically detected from the file extension. Supported formats include: - og.RdfFormat.TURTLE (.ttl) - og.RdfFormat.N_TRIPLES (.nt) - og.RdfFormat.N_QUADS (.nq) - og.RdfFormat.RDF_XML (.rdf, .xml) - og.RdfFormat.JSON_LD (.jsonld) - og.RdfFormat.TRIG (.trig) - og.RdfFormat.N3 (.n3)
context (Optional[Context]) – The named graph (context) to upload statements into. If None, statements are added to the default graph.
base_uri (Optional[str]) – The base URI for resolving relative URIs in the file. If None, relative URIs are resolved based on the file path.
- Raises:
FileNotFoundError – If the specified file doesn’t exist.
RepositoryNotFoundException – If the repository doesn’t exist.
RepositoryUpdateException – If the upload fails.
ValueError – If the RDF format is not supported.
SyntaxError – If the file contains invalid RDF data.
Example
>>> repo = await db.get_repository("my-repo") >>> # Upload a Turtle file (format auto-detected) >>> await repo.upload_file("data.ttl") >>> # Upload to a specific named graph >>> await repo.upload_file("data.ttl", context=IRI("http://example.com/graph")) >>> # Upload with explicit format >>> await repo.upload_file("data.txt", rdf_format=og.RdfFormat.N_TRIPLES)
- class rdf4j_python.AsyncRdf4j(base_url: str)[source]¶
Bases:
objectAsynchronous entry point for interacting with an RDF4J server.
- async create_repository(config: RepositoryConfig) AsyncRdf4JRepository[source]¶
Creates a new RDF4J repository using RDF configuration.
- Parameters:
repository_id (str) – The repository ID to create.
config (RepositoryConfig) – RDF configuration.
- Returns:
An async interface to the newly created repository.
- Return type:
- Raises:
RepositoryCreationException – If repository creation fails.
- async delete_repository(repository_id: str) None[source]¶
Deletes a repository and all its data and configuration.
- Parameters:
repository_id (str) – The ID of the repository to delete.
- Raises:
RepositoryDeletionException – If the deletion fails.
- async get_protocol_version() str[source]¶
Fetches the RDF4J protocol version.
- Returns:
The protocol version string.
- Return type:
str
- Raises:
httpx.HTTPStatusError – If the request fails.
- async get_repository(repository_id: str) AsyncRdf4JRepository[source]¶
Gets an interface to a specific RDF4J repository.
- Parameters:
repository_id (str) – The ID of the repository.
- Returns:
An async interface for the repository.
- Return type:
- async health_check() bool[source]¶
Checks if the RDF4J server is reachable and healthy.
This method attempts to fetch the protocol version from the server to verify connectivity.
- Returns:
- True if the server is reachable and responds correctly,
False otherwise.
- Return type:
bool
Example
>>> async with AsyncRdf4j("http://localhost:8080/rdf4j-server") as db: ... if await db.health_check(): ... print("Server is healthy") ... else: ... print("Server is not reachable")
- async list_repositories() list[RepositoryMetadata][source]¶
Lists all available RDF4J repositories.
- Returns:
A list of repository metadata objects.
- Return type:
list[RepositoryMetadata]
- Raises:
httpx.HTTPStatusError – If the request fails.
- class rdf4j_python.AsyncTransaction(client: AsyncApiClient, repository_id: str, isolation_level: IsolationLevel | None = None)[source]¶
Bases:
objectAsync context manager for transactional operations on an RDF4J repository.
Transactions allow grouping multiple operations (add, delete, update) into a single atomic unit. Either all operations succeed (commit) or none of them take effect (rollback).
- Usage as context manager (recommended):
```python async with repo.transaction() as txn:
await txn.add_statements([quad1, quad2]) await txn.add_statements([quad3]) # Auto-commits on success, auto-rollbacks on exception
- Manual usage:
```python txn = repo.transaction() await txn.begin() try:
await txn.add_statements([quad1, quad2]) await txn.commit()
- except Exception:
await txn.rollback() raise
- state¶
Current state of the transaction (PENDING, ACTIVE, COMMITTED, ROLLED_BACK)
- async add_statements(statements: Iterable[Quad] | Iterable[Triple]) None[source]¶
Add statements to the repository within this transaction.
- Parameters:
statements – The RDF statements to add.
- Raises:
TransactionStateError – If the transaction is not active.
TransactionError – If the operation fails.
- async begin() None[source]¶
Start the transaction.
- Raises:
TransactionStateError – If the transaction has already been started.
TransactionError – If the server fails to create the transaction.
- async commit() None[source]¶
Commit the transaction, making all changes permanent.
- Raises:
TransactionStateError – If the transaction is not active.
TransactionError – If the commit fails.
- async delete_statements(statements: Iterable[Quad] | Iterable[Triple]) None[source]¶
Delete specific statements from the repository within this transaction.
- Parameters:
statements – The RDF statements to delete.
- Raises:
TransactionStateError – If the transaction is not active.
TransactionError – If the operation fails.
- property is_active: bool¶
Returns True if the transaction is active.
- async rollback() None[source]¶
Rollback the transaction, discarding all changes.
- Raises:
TransactionStateError – If the transaction is not active.
TransactionError – If the rollback fails.
- property state: TransactionState¶
Returns the current state of the transaction.
- async update(sparql_update: str) None[source]¶
Execute a SPARQL UPDATE within this transaction.
- Parameters:
sparql_update – The SPARQL UPDATE query string.
- Raises:
TransactionStateError – If the transaction is not active.
TransactionError – If the operation fails.
- class rdf4j_python.BlankNode(value=None)¶
Bases:
objectAn RDF blank node.
- Parameters:
value (str or None, optional) – the blank node identifier (if not present, a random blank node identifier is automatically generated).
- Raises:
ValueError – if the blank node identifier is invalid according to NTriples, Turtle, and SPARQL grammars.
The
strfunction provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(BlankNode('ex')) '_:ex'
- value¶
the blank node identifier. :rtype: str
>>> BlankNode("ex").value 'ex'
- Type:
return
- class rdf4j_python.DefaultGraph¶
Bases:
objectThe RDF default graph name.
- class rdf4j_python.GraphPattern[source]¶
Bases:
objectA composable block of SPARQL graph patterns.
Every mutating method returns
selffor fluent chaining.- bind(expr: str, var: str) GraphPattern[source]¶
Add a
BIND(expr AS ?var)clause.
- copy() GraphPattern[source]¶
Return a deep copy of this pattern.
- filter(expr: str) GraphPattern[source]¶
Add a
FILTER(expr)clause.
- optional(s_or_pattern: str | NamedNode | Variable | Literal | BlankNode | GraphPattern, p: str | NamedNode | Variable | Literal | BlankNode | None = None, o: str | NamedNode | Variable | Literal | BlankNode | None = None) GraphPattern[source]¶
Add an
OPTIONAL { … }block.optional(s, p, o)— single triple shorthandoptional(GraphPattern())— complex pattern block
- sub_query(builder: SelectQuery) GraphPattern[source]¶
Embed a sub-SELECT inside this pattern.
- union(*patterns: GraphPattern) GraphPattern[source]¶
Add
{ … } UNION { … }blocks.
- values(var: str, vals: list[Any]) GraphPattern[source]¶
Add a
VALUES ?var { … }clause.
- rdf4j_python.IRI¶
alias of
NamedNode
- class rdf4j_python.IsolationLevel(value)[source]¶
Bases:
EnumTransaction isolation levels supported by RDF4J.
Note: Not all RDF4J store implementations support all isolation levels. If an unsupported level is requested, the store’s default will be used.
- class rdf4j_python.Literal(value, *, datatype=None, language=None)¶
Bases:
objectAn RDF literal.
- Parameters:
value (str or int or float or bool) – the literal value or lexical form.
datatype (NamedNode or None, optional) – the literal datatype IRI.
language (str or None, optional) – the literal language tag.
- Raises:
ValueError – if the language tag is not valid according to RFC 5646 (BCP 47).
The
strfunction provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Literal('example')) '"example"' >>> str(Literal('example', language='en')) '"example"@en' >>> str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer'))) '"11"^^<http://www.w3.org/2001/XMLSchema#integer>' >>> str(Literal(11)) '"11"^^<http://www.w3.org/2001/XMLSchema#integer>'
- datatype¶
the literal datatype IRI. :rtype: NamedNode
>>> Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer')).datatype <NamedNode value=http://www.w3.org/2001/XMLSchema#integer> >>> Literal('example').datatype <NamedNode value=http://www.w3.org/2001/XMLSchema#string> >>> Literal('example', language='en').datatype <NamedNode value=http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>
- Type:
return
- language¶
the literal language tag. :rtype: str or None
>>> Literal('example', language='en').language 'en' >>> Literal('example').language
- Type:
return
- value¶
the literal value or lexical form. :rtype: str
>>> Literal("example").value 'example'
- Type:
return
- class rdf4j_python.Namespace(prefix: str, namespace: str)[source]¶
Bases:
objectRepresents a namespace in RDF4J.
- classmethod from_sparql_query_solution(query_solution: QuerySolution) Namespace[source]¶
Creates a Namespace from a binding.
- property namespace: NamedNode¶
Returns the namespace URI.
- Returns:
The namespace URI.
- Return type:
IRI
- property prefix: str¶
Returns the prefix of the namespace.
- Returns:
The prefix of the namespace.
- Return type:
str
- exception rdf4j_python.NamespaceException[source]¶
Bases:
Rdf4jErrorException raised when a namespace operation fails.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.NetworkError[source]¶
Bases:
Rdf4jErrorException raised when a network/connection error occurs.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- rdf4j_python.Predicate¶
alias of
NamedNode
- class rdf4j_python.Quad(subject, predicate, object, graph_name=None)¶
Bases:
objectAn RDF triple. in a RDF dataset.
- Parameters:
subject (NamedNode or BlankNode or Triple) – the quad subject.
predicate (NamedNode) – the quad predicate.
object (NamedNode or BlankNode or Literal or Triple) – the quad object.
graph_name (NamedNode or BlankNode or DefaultGraph or None, optional) – the quad graph name. If not present, the default graph is assumed.
The
strfunction provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) '<http://example.com> <http://example.com/p> "1" <http://example.com/g>'
>>> str(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), DefaultGraph())) '<http://example.com> <http://example.com/p> "1"'
A quad could also be easily destructed into its components:
>>> (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))
- graph_name¶
the quad graph name. :rtype: NamedNode or BlankNode or DefaultGraph
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).graph_name <NamedNode value=http://example.com/g>
- Type:
return
- object¶
the quad object. :rtype: NamedNode or BlankNode or Literal or Triple
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).object <Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>
- Type:
return
- predicate¶
the quad predicate. :rtype: NamedNode
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).predicate <NamedNode value=http://example.com/p>
- Type:
return
- subject¶
the quad subject. :rtype: NamedNode or BlankNode or Triple
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).subject <NamedNode value=http://example.com>
- Type:
return
- triple¶
the quad underlying triple. :rtype: Triple
>>> Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')).triple <Triple subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>>
- Type:
return
- rdf4j_python.QuadResultSet¶
alias of
QuadParser
- exception rdf4j_python.QueryError[source]¶
Bases:
Rdf4jErrorException raised when a SPARQL query is invalid or fails.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.Rdf4jError[source]¶
Bases:
ExceptionBase exception for all RDF4J SDK errors.
All exceptions raised by the RDF4J Python SDK inherit from this class, allowing users to catch all SDK-related errors with a single except clause.
Example
- try:
await repo.query(“SELECT * WHERE { ?s ?p ?o }”)
- except Rdf4jError as e:
# Catches any RDF4J SDK error print(f”RDF4J error: {e}”)
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.RepositoryCreationException[source]¶
Bases:
RepositoryErrorException raised when a repository creation fails.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.RepositoryDeletionException[source]¶
Bases:
RepositoryErrorException raised when a repository deletion fails.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.RepositoryError[source]¶
Bases:
Rdf4jErrorBase exception for repository-related errors.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.RepositoryInternalException[source]¶
Bases:
RepositoryErrorException raised when a repository internal error occurs.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class rdf4j_python.RepositoryMetadata(id: str, uri: str, title: str, readable: bool, writable: bool)[source]¶
Bases:
objectRepresents a repository metadata RDF4J.
- classmethod from_sparql_query_solution(query_solution: QuerySolution) RepositoryMetadata[source]¶
Create a RepositoryMetadata instance from a SPARQL query result.
- Parameters:
query_solution (og.QuerySolution) – The SPARQL query result.
- Returns:
The RepositoryMetadata instance.
- Return type:
- Raises:
ValueError – If the query solution is missing required fields.
- exception rdf4j_python.RepositoryNotFoundException[source]¶
Bases:
RepositoryErrorException raised when a repository is not found.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.RepositoryUpdateException[source]¶
Bases:
RepositoryErrorException raised when a repository update fails.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception rdf4j_python.TransactionError[source]¶
Bases:
Rdf4jErrorBase exception for transaction-related errors.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class rdf4j_python.TransactionState(value)[source]¶
Bases:
EnumRepresents the state of a transaction.
- exception rdf4j_python.TransactionStateError[source]¶
Bases:
TransactionErrorException raised when a transaction operation is invalid for the current state.
For example, trying to commit an already committed transaction, or trying to add statements to a closed transaction.
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class rdf4j_python.Triple(subject, predicate, object)¶
Bases:
objectAn RDF triple.
- Parameters:
The
strfunction provides a serialization compatible with NTriples, Turtle, and SPARQL:>>> str(Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) '<http://example.com> <http://example.com/p> "1"'
A triple could also be easily destructed into its components:
>>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))
- object¶
the triple object. :rtype: NamedNode or BlankNode or Literal or Triple
>>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).object <Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>>
- Type:
return
- predicate¶
the triple predicate. :rtype: NamedNode
>>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).predicate <NamedNode value=http://example.com/p>
- Type:
return
- subject¶
the triple subject. :rtype: NamedNode or BlankNode or Triple
>>> Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')).subject <NamedNode value=http://example.com>
- Type:
return
- class rdf4j_python.Variable(value)¶
Bases:
objectA SPARQL query variable.
- Parameters:
value (str) – the variable name as a string.
- Raises:
ValueError – if the variable name is invalid according to the SPARQL grammar.
The
strfunction provides a serialization compatible with SPARQL:>>> str(Variable('foo')) '?foo'
- value¶
the variable name. :rtype: str
>>> Variable("foo").value 'foo'
- Type:
return