lakesuperior.api package¶
Submodules¶
lakesuperior.api.admin module¶
Admin API.
This module contains maintenance utilities and stats.
-
lakesuperior.api.admin.
fixity_check
(uid)[source]¶ Check fixity of a resource.
This calculates the checksum of a resource and validates it against the checksum stored in its metadata (
premis:hasMessageDigest
).Parameters: uid (str) – UID of the resource to be checked. Return type: None Raises: lakesuperior.exceptions.ChecksumValidationError: the cecksums do not match. This indicates corruption. Raises: lakesuperior.exceptions.IncompatibleLdpTypeError: if the resource is not an LDP-NR.
-
lakesuperior.api.admin.
integrity_check
()[source]¶ Check integrity of the data set.
At the moment this is limited to referential integrity. Other checks can be added and triggered by different argument flags.
lakesuperior.api.query module¶
-
lakesuperior.api.query.
fulltext_lookup
(pattern)[source]¶ Look up one term by partial match.
TODO: reserved for future use. A `Whoosh <https://whoosh.readthedocs.io/>`__ or similar full-text index is necessary for this.
-
lakesuperior.api.query.
operands
= ('_id', '=', '!=', '<', '>', '<=', '>=')¶ Available term comparators for term query.
The
_uri
term is used to match URIRef terms, all other comparators are used against literals.
-
lakesuperior.api.query.
sparql_query
(qry_str, fmt)[source]¶ Send a SPARQL query to the triplestore.
Parameters: - qry_str (str) – SPARQL query string. SPARQL 1.1 Query Language (https://www.w3.org/TR/sparql11-query/) is supported.
- fmt (str) – Serialization format. This varies depending on the query type (SELECT, ASK, CONSTRUCT, etc.). [TODO Add reference to RDFLib serialization formats]
Return type: BytesIO
Returns: Serialized SPARQL results.
-
lakesuperior.api.query.
term_query
(terms, or_logic=False)[source]¶ Query resources by predicates, comparators and values.
Comparators can be against literal or URIRef objects. For a list of comparators and their meanings, see the documentation and source for
operands
.Parameters: - terms (list(tuple{3})) –
List of 3-tuples containing:
- Predicate URI (rdflib.URIRef)
- Comparator value (str)
- Value to compare to (rdflib.URIRef or rdflib.Literal or str)
- or_logic (bool) – Whether to concatenate multiple query terms with OR
logic (uses SPARQL
UNION
statements). The default is False (i.e. terms are concatenated as standard SPARQL statements).
- terms (list(tuple{3})) –
-
lakesuperior.api.query.
triple_match
(s=None, p=None, o=None, return_full=False)[source]¶ Query store by matching triple patterns.
Any of the
s
,p
oro
terms can be None to represent a wildcard.This method is for triple matching only; it does not allow to query, nor exposes to the caller, any context.
Parameters: - s (rdflib.term.Identifier) – Subject term.
- p (rdflib.term.Identifier) – Predicate term.
- o (rdflib.term.Identifier) – Object term.
- return_full (bool) – if
False
(the default), the returned values in the set are the URIs of the resources found. If True, the full set of matching triples is returned.
Return type: Returns: Matching resource URIs if
return_full
is false, or matching triples otherwise.
lakesuperior.api.resource module¶
Primary API for resource manipulation.
Quickstart:
>>> # First import default configuration and globals—only done once.
>>> from lakesuperior import env
>>> env.setup()
>>> from lakesuperior.api import resource
>>> # Get root resource.
>>> rsrc = resource.get('/')
>>> # Dump graph.
>>> with rsrc.imr.store.txn_ctx():
>>> print({*rsrc.imr.as_rdflib()})
{(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://purl.org/dc/terms/title'),
rdflib.term.Literal('Repository Root')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://fedora.info/definitions/fcrepo#Container')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://fedora.info/definitions/fcrepo#RepositoryRoot')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://fedora.info/definitions/fcrepo#Resource')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://www.w3.org/ns/ldp#BasicContainer')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://www.w3.org/ns/ldp#Container')),
(rdflib.term.URIRef('info:fcres/'),
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
rdflib.term.URIRef('http://www.w3.org/ns/ldp#RDFSource'))}
-
lakesuperior.api.resource.
create
(parent, slug=None, **kwargs)[source]¶ Mint a new UID and create a resource.
The UID is computed from a given parent UID and a “slug”, a proposed path relative to the parent. The application will attempt to use the suggested path but it may use a different one if a conflict with an existing resource arises.
Parameters: Return type: Returns: A tuple of: 1. Event type (str): whether the resource was created or updated. 2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated resource.
-
lakesuperior.api.resource.
create_or_replace
(uid, **kwargs)[source]¶ Create or replace a resource with a specified UID.
Parameters: - uid (string) – UID of the resource to be created or updated.
- **kwargs – Other parameters are passed to the
from_provided()
method.
Return type: Returns: A tuple of: 1. Event type (str): whether the resource was created or updated. 2. Resource (lakesuperior.model.ldp.ldpr.Ldpr): The new or updated
resource.
-
lakesuperior.api.resource.
create_version
(uid, ver_uid)[source]¶ Create a resource version.
Parameters: - uid (string) – Resource UID.
- ver_uid (string) – Version UID to be appended to the resource URI. NOTE: this is a “slug”, i.e. the version URI is not guaranteed to be the one indicated.
Return type: Returns: Version UID.
-
lakesuperior.api.resource.
delete
(uid, soft=True, inbound=True)[source]¶ Delete a resource.
Parameters: - uid (string) – Resource UID.
- soft (bool) – Whether to perform a soft-delete and leave a tombstone resource, or wipe any memory of the resource.
-
lakesuperior.api.resource.
exists
(uid)[source]¶ Return whether a resource exists (is stored) in the repository.
Parameters: uid (string) – Resource UID.
-
lakesuperior.api.resource.
get
(uid, repr_options={})[source]¶ Get an LDPR resource.
The resource comes preloaded with user data and metadata as indicated by the repr_options argument. Any further handling of this resource is done outside of a transaction.
Parameters: - uid (string) – Resource UID.
- repr_options – (dict(bool)) Representation options. This is a dict that is unpacked downstream in the process. The default empty dict results in default values. The accepted dict keys are:
- incl_inbound: include inbound references. Default: False.
- incl_children: include children URIs. Default: True.
- embed_children: Embed full graph of all child resources. Default: False
-
lakesuperior.api.resource.
get_metadata
(uid)[source]¶ Get metadata (admin triples) of an LDPR resource.
Parameters: uid (string) – Resource UID.
-
lakesuperior.api.resource.
resurrect
(uid)[source]¶ Reinstate a buried (soft-deleted) resource.
Parameters: uid (str) – Resource UID.
-
lakesuperior.api.resource.
revert_to_version
(uid, ver_uid)[source]¶ Restore a resource to a previous version state.
Parameters:
-
lakesuperior.api.resource.
transaction
(write=False)[source]¶ Handle atomic operations in a store.
This wrapper ensures that a write operation is performed atomically. It also takes care of sending a message for each resource changed in the transaction.
ALL write operations on the LDP-RS and LDP-NR stores go through this wrapper.
-
lakesuperior.api.resource.
update
(uid, update_str, is_metadata=False, handling='strict')[source]¶ Update a resource with a SPARQL-Update string.
Parameters: - uid (string) – Resource UID.
- update_str (string) – SPARQL-Update statements.
- is_metadata (bool) – Whether the resource metadata are being updated.
- handling (str) – How to handle server-managed triples.
strict
(the default) rejects the update with an exception if server-managed triples are being changed.lenient
modifies the update graph so offending triples are removed and the update can be applied.
Raises: InvalidResourceError – If
is_metadata
is False and the resource being updated is a LDP-NR.