API Documentation¶
Database Client¶
- class delb_existdb.ExistClient(**options: ClientOptions)¶
Bases:
objectAn eXist-db client object to interact with a database instance. The client can be used for CRUD operations. Nodes can be queried using an XPath expression. Queried resources are identified by a document and a node ID (these map to eXist-db’s absolute and relative resource IDs).
Caution
The node IDs are mere pointers by index to a node within a document. Structural changes to a document may invalidate these and lead to undesired behaviour.
- Parameters:
host – The name of the database serving host.
port – The port the database instance is listening to.
user – An optional username to authenticate.
password – The accompanying password for authentication.
prefix – The HTTP path prefix for the database instance.
collection – The path to the collection which will be used as root for all document paths.
parser_options – A named tuple from delb to define the XML parser’s behaviour.
- property collection: str¶
The collection for database queries. The attribute can be changed on an initialized client.
- delete_document(path: str) None¶
Removes a document from the associated database.
- Parameters:
path – The path pointing to the document within the collection.
- delete_node(document_id: str, node_id: str = '') None¶
Remove a node from the database.
- Parameters:
document_id – The absolute resource ID pointing to the document.
node_id – The node ID locating a node inside a document (optional).
- fetch_document(path: str) Document¶
Fetches a document from the client’s configured collection.
- Parameters:
path – Path of the document.
- fetch_node(document_id: str, node_id: str) NodeResource¶
Retrieve a node resource by its internal database IDs.
- Parameters:
document_id – The ID of a document.
node_id – The node ID locating a node inside a document (optional).
- Returns:
The queried resource object.
- classmethod from_url(url: str, parser_options: ParserOptions | None = None) ExistClient¶
Returns a client instance from the given URL. Path parts that point to something beyond the database instance’s path prefix are ignored.
- property parser_options: ParserOptions¶
- query(query_expression: str) TagNodeType¶
Make a database query using XQuery. The configured collection will be the starting point of the query.
- Parameters:
query_expression – XQuery expression.
- Returns:
The query result as a
delb.TagNodeobject.
- retrieve_resource(abs_resource_id: str, node_id: str) NodeResource¶
Deprecated. Use
ExistClient.fetch_node()
- update_node(node: TagNodeType, document_id: str, node_id: str)¶
Replace a node with the contents of the given one.
- Parameters:
node – An XML node to replace the old one with.
document_id – The document ID of the target.
node_id – The node ID locating the node inside the containing document.
- xpath(expression: str) list[NodeResource]¶
Retrieve a set of resources from the database using an XPath expression. The configured collection will be the starting point of the query.
- Parameters:
expression – XPath expression (whatever version your eXist instance supports via its RESTful API)
- Returns:
The query results as a list of
NodeResourceobjects.
Resources¶
- class delb_existdb.NodeResource(exist_client: ExistClient, query_result: QueryResultItem)¶
Bases:
objectA representation of an XML node in a eXist-db resource. Each object is coupled to an
ExistClient. Resources are identified by a document ID that points to the containing document and a node ID within that document.- property abs_resource_id¶
- delete()¶
Deletes the node from the database.
- property document_id¶
The absolute resource ID pointing to a document in the database.
- property document_path¶
The resource path pointing to the document.
- node¶
A delb node representation of the node.
- property node_id¶
The node ID locating the node relative to the containing document.
- update_pull()¶
Retrieve the current node state from the database and update the object.
- update_push()¶
Writes the current
NodeResource.nodecontents to the database, replacing the previous state.
delb plugins¶
- class delb_existdb.delb_plugins.ExistDBExtension¶
Bases:
DocumentMixinBaseThis class provides extensions to
delb.Documentin order to interact with a eXist-db instance.See
existdb_loader()on retrieving documents from an eXist-db instance.- config: SimpleNamespace¶
- property existdb_collection: str¶
The collection within an eXist-db instance where the document was fetched from. This property can be changed to designate another location to store to.
- existdb_delete()¶
Deletes the document that currently resides at the location which is made up of the current
ExistDBExtension.existdb_collectionandExistDBExtension.existdb_filepathin the associated eXist-db instance.
- property existdb_filepath: str¶
The filepath within the eXist-db instance and collection where the document was fetched from. This property can be changed to designate another location to store to.
- existdb_store(collection: str | None = None, filepath: str | None = None, replace_existing: bool = False)¶
Stores the current state of the document in the associated eXist-db instance.
- Parameters:
collection – An alternate collection to save into.
filepath – An alternate path to store the document.
replace_existing – Allows to overwrite existing documents.
- delb_existdb.delb_plugins.existdb_loader(source: Any, config: SimpleNamespace) LoaderResult¶
This loader loads a document from a eXist-db instance. There are two ways to retrieve a particular document.
One is to specify an URL with the
existdb://scheme, which can optionally be extended with the transport protocol:existdb+http://orexistdb+https://.The overall pattern of the URLs is:
existdb[+http[s]]://[[<username>]:[<password>]@]<host>[:<port>][ /<prefix>]/<path>
For example:
document = delb.Document("existdb://example.org/exist/corpus/document.xml")
Note that omitted ports would default to
80or443respectively, depending on the used transport protocol. Which in turn is probed for if not specified, preferring encrypted connections.The other way is to pass a configured client as
existdb_clientkeyword and a path as string orpathlib.PurePosixPaththat points to the document within the client’s configureddelb_existdb.ExistClient.collection, hence this would be an equivalent to the example above, assuming thathttpsis available on the addressed host:client = delb_existdb.ExistClient( transport="https", host="example.org", port=443, user="", collection="/corpus", ) document = delb.Document("document.xml", existdb_client=client)
In both cases the document instance will have a configured
confignamespaceexistdbwith the propertyclientwhich is adelb_existdb.ExistClientinstance.Further interaction with the database is facilitated with the
ExistDBExtensionthat extends thedelb.Documentclass.
Exceptions¶
- exception delb_existdb.exceptions.DelbExistdbConfigError¶
Bases:
DelbExistdbErrorRaised if the database connection is improperly configured.
- exception delb_existdb.exceptions.DelbExistdbError¶
Bases:
ExceptionDelbExistdb base exception class.
- exception delb_existdb.exceptions.DelbExistdbNotFound¶
Bases:
DelbExistdbReadErrorRaised if a database resource is not found.
- exception delb_existdb.exceptions.DelbExistdbQueryError(payload: str, response: httpx.Response)¶
Bases:
DelbExistdbErrorInforms about query errors.
- path¶
- payload¶
- exception delb_existdb.exceptions.DelbExistdbReadError¶
Bases:
DelbExistdbErrorRaised if a writing operation fails.
- exception delb_existdb.exceptions.DelbExistdbWriteError¶
Bases:
DelbExistdbErrorRaised if a reading operation fails