labapi.user.User#

class labapi.user.User(
uid: str,
email: str,
notebooks: Sequence[NotebookInit],
client: Client,
)[source]#

Bases: object

Represents an authenticated LabArchives user session.

This class holds user-specific information such as the user ID and provides an interface to interact with the LabArchives API, particularly for accessing and managing notebooks and their contents.

__init__(
uid: str,
email: str,
notebooks: Sequence[NotebookInit],
client: Client,
)[source]#

Initialize a user session.

Parameters:
  • uid – The unique ID of the user.

  • email – The email address of the user.

  • notebooks – A sequence of NotebookInit objects representing the notebooks accessible to the user.

  • client – The Client instance used for API communication.

Methods

__init__(uid, email, notebooks, client)

Initialize a user session.

api_get(api_method_uri, **kwargs)

Send a GET request on behalf of this user.

api_post(api_method_uri, body, **kwargs)

Send a POST request on behalf of this user.

get_max_upload_size()

Return the effective attachment upload size limit in bytes.

Attributes

client

The Client instance associated with this user session.

email

The email address of the user.

id

The unique ID of the user.

notebooks

The user's notebooks.

property id: str#

The unique ID of the user.

property email: str#

The email address of the user.

property client: Client#

The Client instance associated with this user session.

api_get(
api_method_uri: str | Sequence[str],
**kwargs: Any,
)[source]#

Send a GET request on behalf of this user.

This method automatically appends the user’s ID to the API call.

Parameters:
  • api_method_uri – The API method URI (e.g., “get_user_settings”). Can be a string or a sequence of strings representing path segments.

  • kwargs – Additional query parameters to pass to the API method.

Returns:

The response from the API, typically an lxml.etree.Element.

Raises:
  • RuntimeError – If the underlying client session has been closed.

  • AuthenticationError – If LabArchives rejects the request due to invalid or expired credentials.

  • ApiError – If LabArchives returns any other non-success response.

Invalid XML propagates lxml.etree.XMLSyntaxError.

api_post(
api_method_uri: str | Sequence[str],
body: Mapping[str, str] | IO[bytes] | IO[str],
**kwargs: Any,
)[source]#

Send a POST request on behalf of this user.

This method automatically appends the user’s ID to the API call.

Parameters:
  • api_method_uri – The API method URI (e.g., “create_entry”). Can be a string or a sequence of strings representing path segments.

  • body – The request body, which can be a mapping of form data or a file-like object.

  • kwargs – Additional query parameters to pass to the API method.

Returns:

The response from the API, typically an lxml.etree.Element.

Raises:
  • RuntimeError – If the underlying client session has been closed.

  • AuthenticationError – If LabArchives rejects the request due to invalid or expired credentials.

  • ApiError – If LabArchives returns any other non-success response.

Invalid XML propagates lxml.etree.XMLSyntaxError.

get_max_upload_size() → int[source]#

Return the effective attachment upload size limit in bytes.

The account’s reported max-file-size (users/max_file_size) can exceed what the API upload endpoint accepts: entries/add_attachment is capped at 250 MiB (262_144_000 bytes) by an nginx client_max_body_size on the API tier. This returns the smaller of the two, so the value reflects what an add_attachment upload will actually accept (larger files must use the web/S3 upload path).

Returns:

The effective upload size limit in bytes.

Raises:

Invalid XML propagates lxml.etree.XMLSyntaxError.

property notebooks: Notebooks#

The user’s notebooks.

Returns:

A Notebooks object managing the user’s notebooks.