nexusLIMS.utils.labarchives#
Low-level API client for LabArchives electronic lab notebook.
This module provides a reusable client for interacting with the LabArchives API. Authentication uses HMAC-SHA-512 signed requests (akid + method + expires, keyed with the access password).
LabArchives API documentation: https://api.labarchives.com/api_docs/
Example usage: >>> from nexusLIMS.utils.labarchives import get_labarchives_client >>> client = get_labarchives_client() >>> nodes = client.get_tree_level(“12345”, “0”) >>> for node in nodes: … print(f”{node[‘tree_id’]}: {node[‘display_text’]}”) >>> folder_id = client.insert_folder(“12345”, “0”, “My Folder”) >>> page_id = client.insert_page(“12345”, folder_id, “My Page”)
Module Contents#
Classes#
Low-level client for the LabArchives API. |
Functions#
Get configured LabArchives client from settings. |
API#
- exception nexusLIMS.utils.labarchives.LabArchivesError[source]#
Bases:
ExceptionBase exception for LabArchives API errors.
- exception nexusLIMS.utils.labarchives.LabArchivesAuthenticationError[source]#
Bases:
nexusLIMS.utils.labarchives.LabArchivesErrorAuthentication failed (invalid credentials or session expired).
- exception nexusLIMS.utils.labarchives.LabArchivesPermissionError[source]#
Bases:
nexusLIMS.utils.labarchives.LabArchivesErrorInsufficient permissions for the requested operation.
- exception nexusLIMS.utils.labarchives.LabArchivesNotFoundError[source]#
Bases:
nexusLIMS.utils.labarchives.LabArchivesErrorRequested resource not found.
- exception nexusLIMS.utils.labarchives.LabArchivesRateLimitError[source]#
Bases:
nexusLIMS.utils.labarchives.LabArchivesErrorServer error or rate limit exceeded (5xx response).
- class nexusLIMS.utils.labarchives.LabArchivesClient(base_url: str, akid: str, password: str, uid: str)[source]#
Low-level client for the LabArchives API.
Authentication uses HMAC-SHA-512 signed requests. Each request includes:
akid: Access Key IDexpires: Unix timestamp in millisecondssig: URL-encoded base64 HMAC-SHA-512 signature ofakid + method + expires
- Parameters:
Examples:
>>> client = LabArchivesClient( ... base_url="https://api.labarchives.com/api", ... akid="your-akid", ... password="your-password", ... uid="your-uid", ... ) >>> nodes = client.get_tree_level("12345", "0")
- get_tree_level(nbid: str, parent_tree_id: str = '0') list[dict[str, Any]][source]#
Get child nodes at a tree level in a notebook.
- Parameters:
- Returns:
Each dict has
tree_id,display_text, andis_pagekeys.- Return type:
- Raises:
LabArchivesError – If the API call fails
- get_page_entries(nbid: str, page_tree_id: str, *, include_content: bool = False) list[dict[str, Any]][source]#
Get all entries on a notebook page.
- Parameters:
- Returns:
Each dict has
eidandpart_typekeys, plusentry_datawhen include_content is True.- Return type:
- Raises:
LabArchivesError – If the API call fails
- insert_folder(nbid: str, parent_tree_id: str, name: str) str[source]#
Create a folder in a notebook tree.
- Parameters:
- Returns:
The
tree_idof the newly created folder- Return type:
- Raises:
LabArchivesError – If the API call fails
- insert_page(nbid: str, parent_tree_id: str, name: str) str[source]#
Create a page in a notebook tree.
- Parameters:
- Returns:
The
tree_idof the newly created page- Return type:
- Raises:
LabArchivesError – If the API call fails
- add_entry(nbid: str, page_tree_id: str, entry_data: str, part_type: str = 'text entry') str[source]#
Add a text/HTML entry to a notebook page.
- Parameters:
- Returns:
The
eid(entry ID) of the newly created entry- Return type:
- Raises:
LabArchivesError – If the API call fails
- add_attachment(nbid: str, page_tree_id: str, filename: str, data: bytes, caption: str = '') str[source]#
Upload a file attachment to a notebook page.
- Parameters:
- Returns:
The
eid(entry ID) of the attachment entry- Return type:
- Raises:
LabArchivesError – If the API call fails
- attach_file(nbid: str, page_tree_id: str, path: Path, caption: str = '') str[source]#
Upload a file from disk as an attachment to a notebook page.
Convenience wrapper around
add_attachment()that reads the file and derives the filename from the path automatically.- Parameters:
- Returns:
The
eid(entry ID) of the attachment entry- Return type:
- Raises:
LabArchivesError – If the API call fails
- get_attachment_content(eid: str) bytes[source]#
Download the raw content of an attachment entry.
- Parameters:
eid (str) – Entry ID of the attachment (as returned by
add_attachment())- Returns:
Raw file content of the attachment
- Return type:
- Raises:
LabArchivesNotFoundError – If the entry does not exist
LabArchivesError – If the API call fails
- get_user_info(login: str, password: str) dict[str, Any][source]#
Exchange login credentials for user info and notebook list.
This method is used to obtain the
uidfor a LabArchives account. The returneduidshould be stored inNX_LABARCHIVES_USER_IDfor subsequent API calls.- Parameters:
- Returns:
User info including
uid,email, andnotebookslist.- Return type:
- Raises:
LabArchivesAuthenticationError – If login credentials are invalid
LabArchivesError – If the API call fails
- get_user_info_by_uid(uid: str | None = None) dict[str, Any][source]#
Fetch user info for a LabArchives account using a uid.
Calls the
users/user_info_via_idendpoint, which requires only the uid (no login password). When uid is omitted the client’s ownuidis used.- Parameters:
uid (str, optional) – LabArchives user ID. Defaults to the client’s configured uid.
- Returns:
User info including
uid,email, andnotebookslist.- Return type:
- Raises:
LabArchivesError – If the API call fails
- nexusLIMS.utils.labarchives.get_labarchives_client() LabArchivesClient[source]#
Get configured LabArchives client from settings.
Creates a
LabArchivesClientusing credentials from the NexusLIMS configuration (NX_LABARCHIVES_*settings).- Returns:
Configured client instance
- Return type:
- Raises:
LabArchivesError – If required settings are not configured
Examples:
>>> from nexusLIMS.utils.labarchives import get_labarchives_client >>> client = get_labarchives_client() >>> nodes = client.get_tree_level("12345", "0") >>> folder_id = client.insert_folder("12345", "0", "My Folder") >>> page_id = client.insert_page("12345", folder_id, "My Page")