Records Controller

Module containing the Records Controller class for interact with the Records API.

class genomcore.controllers.records.RecordsController(*args, **kwargs)

Bases: BaseController

Records Controller class to interact with the records API. Records API docs: https://records-api.genomcore.net/api/docs

create_records(template: str, body: dict)

Create records v4.

Parameters:
  • template (str) – Template slug or template ID.

  • body (dict) – A JSON object with a list of dictionaries containing the records to create.

Note

The body should have the following JSON structure:

body = {
    "items": [
        {
            "code": "Test_code",
            "data": {
                "Record_parameter": {
                    "parameter_1": "value_1",
                    "parameter_2": "value_2"
                },
                "Record_parameter_2": {
                    "parameter_3": "value_3",
                    "parameter_4": "value_4"
                }
            }
        }
    ]
}

Reminder: The method only allows creating records on one specified template per each request.

Warning

Each record must have a unique code within the template. If you provide a code that already exists, it will raise an error. This method does not validate if all required fields of the template are present in the body.

Returns:

A JSON response with the created record parameters.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")

# Create a single record on "Test_1" template
body = {
    "items": [
        {
            "code": "Test_code",
            "data": {
                "Record_parameter": {
                    "parameter_1": "value_1",
                    "parameter_2": "value_2"
                }
            }
        }
    ]
}

api.records.create_records(template = "Test_1", body = body)

#Create multiple records on "Test_1" template
body = {
    "items": [
        {
            "code": "Test_code",
            "data": {
                "Record_parameter": {
                    "parameter_1": "value_1",
                    "parameter_2": "value_2",
                }
            }
        },
        {
            "code": "Test_code2",
            "data": {
                "Record_parameter": {
                    "parameter_1": "value_3",
                    "parameter_2": "value_4",
                }
            }
        }
    ]
}

api.records.create_records(template = "Test_1", body = body)
update_multiple_records(body: dict)

Update records v2.

update_records(body: dict, id: str | None = None, templateSlug: str | None = None, code: str | None = None)

Update records v4.

Parameters:
  • body (dict) – A Python dictionary containing the new data to update the record.

  • id (str, optional) – The ID of the record to update.

  • templateSlug (str, optional) – The template slug of the record to update.

  • code (str, optional) – The code of the record to update

Warning

The method only allows updating one record per request.

Returns:

A JSON response with the updated record.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")

body = {
    "data": {
        "RecordParameter": {
            "Parameter1": "Value1",
            "Parameter2": "Value2"
        }
    }
}

api.records.update_records(id = "TestID", body = body)
get_records(id: str | None = None, templateSlug: str | None = None, code: str | None = None)

Search records v4.

Parameters:
  • id (str, optional) – The record ID to search.

  • templateSlug (str, optional) – The template slug of the record to search.

  • code (str, optional) – The code of the record to search.

Returns:

A JSON response with the retrieved record parameters.

Note

You must provide either the record ID or the template slug and code to get record information. If you are not providing an ID, then you must provide a template slug and a code.

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")

# Search a record by ID
api.records.get_records(id='test_id')

# Search a record by template slug and code
api.records.get_records(templateSlug='test_template', code='test_code')
query_records(filters, group=None, sort=None, project=None, page=None, pageSize=None, templateId=None)
delete_records(body: List[dict] | None = None, id: str | None = None, templateSlug: str | None = None, code: str | None = None)

Delete records v4.

Parameters:
  • id (str, optional) – The record ID to delete.

  • templateSlug (str, optional) – The template slug of the record to delete.

  • code (str, optional) – The code of the record to delete.

  • body (List[dict], optional) – JSON containing a list of dictionaries with the records to delete.

Returns:

A JSON response with the deleted record parameters.

Note

You must provide either the record ID or the template slug and code to delete a record. If you are not providing an ID, then you must provide a template slug and a code.

Note

The body for deleting records should have the following structure:

body = {
“records”: [

{ “id”: “test_id” }, { “id”: “test_id2” }

]

}

Example:

from genomcore.client import Genomcore

api = Genomcore(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")

# Delete a record by ID
api.records.delete_records(id='test_id')

# Delete a record by template slug and code
api.records.delete_records(templateSlug='test_template', code='test_code')

# Delete multiple records by a JSON structured body
body_delete = {"records": [
        {
            "id": "test_id"
        },
        {
            "id": "test_id2"
        }
    ]
}

api.records.delete_records(body=body_delete)
__annotations__ = {}
__firstlineno__ = 14
__static_attributes__ = ('_requester',)