sampledbapi.objects module

class sampledbapi.objects.Comment(d: Dict)[source]

Bases: SampleDBObject

comment_id: int | None = None
content: str | None = None
object_id: int | None = None
user_id: int | None = None
utc_datetime: datetime | None = None
class sampledbapi.objects.File(d: Dict)[source]

Bases: SampleDBObject

base64_content: str | None = None
file_id: int | None = None
hash: str | None = None
object_id: int | None = None
original_file_name: str | None = None
storage: str | None = None
url: str | None = None
class sampledbapi.objects.Object(d: Dict, users_cache: Dict[int, User] | None = None)[source]

Bases: SampleDBObject

action_id: int | None = None
data: dict | None = None
classmethod from_json(data: dict) Object | None[source]
get_all_group_permissions() Dict[source]

Get a mapping of basic group IDs to their permissions.

Returns:

Mapping of group IDs to permissions.

Return type:

Dict

get_all_project_group_permissions() Dict[source]

Get a mapping of project group IDs to their permissions.

Returns:

Mapping of project group IDs to permissions.

Return type:

Dict

get_all_user_permissions() Dict[source]

Get a mapping of user IDs to their permissions.

Returns:

Mapping of user IDs to permissions.

Return type:

Dict

get_comment(comment_id: int) Comment[source]

Get specific comment (comment_id).

Parameters:

comment_id (int) – ID of the comment.

Returns:

Requested Comment.

Return type:

Object

get_comment_list() List[Comment][source]

Get a list of all comments.

Returns:

List of Comment.

Return type:

List

get_file(file_id: int) File[source]

Get a specific file (file_id).

Parameters:

file_id (int) – ID of the file.

Returns:

See here.

Return type:

Dict

get_file_list() List[source]

Get a list of all files.

Returns:

See here.

Return type:

List

get_group_permissions(group_id: int) str[source]

Get the permissions of a basic group.

Parameters:

group_id (int) – ID of the group.

Returns:

Permissions of group for the object.

Return type:

str

get_location_occurence(location_id: int) LocationOccurence[source]

Get a specific object location assignment (index) for a specific object.

Parameters:

location_id (int) – ID of the location

Returns:

See here.

Return type:

LocationOccurence

get_location_occurences() List[LocationOccurence][source]

Get a list of all object locations assignments for a specific object.

Args:

Returns:

See here.

Return type:

List

get_project_group_permissions(project_id: int) str[source]

Get the permissions of a project group.

Parameters:

project_id (int) – ID of the project group.

Returns:

Permissions of project group for the object.

Return type:

str

get_public() bool[source]

Get whether or not the object is public.

Returns:

Whether the object is public or not.

Return type:

bool

Gets objects related to an object.

Returns:

Two lists containing referenced objects and referencing objects.

get_user_permissions(user_id: int) str[source]

Get the permissions of a user.

Parameters:

user_id (int) – ID of the user.

Returns:

Permissions of user for the object.

Return type:

str

get_version(version_id: int) Object[source]

Get the specific version (version_id).

Parameters:

version_id (int) – ID of the version to be retrieved.

Returns:

Requested Object.

Return type:

Object

object_id: int | None = None
post_comment(comment: str) Response[source]

Create a new comment.

Parameters:

comment (str) – Comment to be posted.

Returns:

See here.

Return type:

HTTPResponse

Create a new file with url storage.

Parameters:

url (str) – URL to be stored.

Returns:

See here.

Return type:

HTTPResponse

schema: dict | None = None
set_group_permissions(group_id: int, permissions: str) Response[source]

Set the permissions of a basic group.

Parameters:
  • group_id (int) – ID of the group.

  • permissions (str) – Permissions of group for the object.

Returns:

See here.

Return type:

HTTPResponse

set_project_group_permissions(project_id: int, permissions: str) Response[source]

Set the permissions of a project group.

Parameters:
  • project_id (int) – ID of the project group.

  • permissions (str) – Permissions of project group for the object.

Returns:

See here.

Return type:

HTTPResponse

set_public(public: bool) Response[source]

Set whether or not the object is public.

Parameters:

public (bool) – Whether the object is public or not.

Returns:

See here.

Return type:

HTTPResponse

set_user_permissions(user_id: int, permissions: str) Response[source]

Set the permissions of a user.

Parameters:
  • user_id (int) – ID of the user.

  • permissions (str) – Permissions of user for the object.

Returns:

See here.

Return type:

HTTPResponse

to_json() Dict[source]
update(data: dict, schema: dict | None = None) Response[source]

Create a new version.

The data is a dictionary that has to be formatted according to the action’s schema. Exemplary data:

{"name": {
    "_type": "text",
    "text": "Example Object"
}}
upload_file(path: str, name: str | None = None) int[source]

Create a new file.

Parameters:

path (str) – Path of the file to be uploaded.

Returns:

See here.

Return type:

HTTPResponse

upload_file_raw(name: str, file_obj: BinaryIO) int[source]

Create a new file with local storage.

Parameters:
  • name (str) – Name that the file will have online.

  • file_obj (BinaryIO) – A binary stream that can be read to be uploaded.

Returns:

See here.

Return type:

HTTPResponse

version_datetime: datetime | None = None
version_editor: User | None = None
version_id: int | None = None
sampledbapi.objects.create(action_id: int, data: dict) int[source]

Create a new object.

The data is a dictionary that has to be formatted according to the action’s schema. Exemplary data:

{"name": {
    "_type": "text",
    "text": "Example Object"
}}
Return type:

int

sampledbapi.objects.get(object_id: int) Object[source]

Get the current version of an object (object_id).

Parameters:

object_id (int) – ID of the object.

Returns:

Requested Object.

Return type:

Object

sampledbapi.objects.get_list(q: str = '', action_id: int = -1, action_type: str = '', limit: int = -1, offset: int = -1, name_only: bool = False) List[Object][source]

Get a list of all objects visible to the current user.

The list only contains the current version of each object. By passing the parameter q to the query, the Advanced Search can be used. By passing the parameters action_id or action_type objects can be filtered by the action they were created with or by their type (e.g. sample or measurement).

Instead of returning all objects, the parameters limit and offset can be used to reduce to maximum number of objects returned and to provide an offset in the returned set, so allow simple pagination.

If the parameter name_only is provided, the object data and schema will be reduced to the name property, omitting all other properties and schema information.

Parameters:
  • q (str) – Search string for advanced search, see here.

  • action_id (int) – Filter by action ID.

  • action_type (str) – Filter by action type.

  • limit (int) – Limit number of results (helpful for pagination).

  • offset (int) – Offset for limited retrieval of results (pagination).

  • name_only (bool) – Only names will be returned, no other information.

Returns:

List of Object.

Return type:

List