benchling.utils.write_entity
class
NamingStrategy
Different options for handling naming when creating custom entities.
See: https://help.benchling.com/hc/en-us/articles/9684227098893-Choose-a-naming-option-for-your-Registry-schema
function
register_entity
Register custom entity to Benchling registry with retry logic
Parameters
benchling_context : BenchlingContext
Benchling context object to get connection
entity_id : str
ID of the entity to register
registry_id : str
ID of the registry to register the entity to
Raises
RegistrationError
Failure to register entity to registry
function
create_custom_entity
Creates and returns the id of the custom entity.
Parameters
benchling_context : Benchling Context object
Benchling context object to get connection
entity_name : str
Name of new entity to be created
folder_id : str | Unset
Folder ID containing Benchling entity to be created. This should be a string starting with
"lib_"
input_schema_id : str | Unset
Input schema ID Tag. schema associated with Benchling entity to be created This should be
a string starting with "ts_"
registry_id : str | Unset
Project associated with custom entity. This identifies the registry that your run entity
will be registered to. This can be found by clicking on Avatar - Feature Settings -
Registry Settings, and you will be able to find it in the URL. This should be a string
starting with "src_"
custom_entity_fields : dict | None
Fields associated with Benchling entity
author_id : str | None
Author ID to associate with custom entity. Should be a string starting with "ent_"
naming_strategy : NamingStrategy
Strategy to use for naming the entity. See NamingStrategy for more details.
Returns
dict[str, str]
Dictionary with custom entity name as key and custom entity ID as value
Raises
BenchlingError
Failure to create entity
function
update_custom_entity
Updates custom entity
Parameters
benchling_context : BenchlingContext
Benchling Context object
existing_entity : benchling_api_client.v2.stable.models.custom_entity.CustomEntity
Existing custom entity to be updated
folder_id : str
Folder ID containing Benchling entity to be created. This should be a string starting with
"lib_"
input_schema_id : str
Input schema ID Tag. schema associated with Benchling entity to be updated. This should be
a string starting with "ts_"
registry_id : str
Project associated with custom entity. This identifies the registry that your run entity
will be registered to. This can be found by clicking on Avatar - Feature Settings -
Registry Settings, and you will be able to find it in the URL. This should be a string
starting with "src_"
custom_entity_fields : dict | None
Fields associated with Benchling entity
Returns
dict[str, str]
Dictionary of entity name, custom entity id pair
function
create_benchling_ids_from_files
Upload blob files to Benchling and return a dictionary where the keys are the file names and the
values are the benchling IDs
Parameters
benchling_context : Benchling Context object
Benchling context object to get connection
file_name : list[str]
File names to associate to file content
file_content : list[bytes] | list[pd.DataFrame]
Blob or data content to upload
keys_as_benchling_name : bool
Use to process file_name for benchling by converting string to lowercase and removing
periods. Default is False.
Returns
dict[str, Unset | str]
Returns a dictionary of IDs from benchling_sdk.models.Blob
function
create_benchling_ids_from_file
Get output file id for blob or data created from bytes.
Parameters
benchling_context : Benchling Context object
Benchling context object to get connection
file_name : str
File name to associate with data
file_content : bytes
Blob or data to upload as a file
Returns
str
Returns the id of benchling_sdk.models.Blob
function
create_benchling_ids_from_data_file
Get output file id for blob created from bytes.
Parameters
benchling_context : Benchling Context object
Benchling context object to get connection
file_name : str
File name to associate with data
df : pd.DataFrame
Data frame to upload as a file
Returns
str
Returns the id of benchling_sdk.models.Blob
function
create_benchling_ids_from_blob_file
Get output file id for blob created from bytes.
Parameters
benchling_context : Benchling Context object
Benchling context object to get connection
blob_name : str
File name to associate with data
blob : bytes
Blob to upload as a file.
Returns
str
Returns the id of benchling_sdk.models.Blob
Notes
The file type is necessary to upload to benchling which is guessed based on the blob_name using
the mimetypes package.
function
create_assay_results_from_dataframe
Processes input DataFrame for upload to Benchling.
Parameters
data : pd.DataFrame
Tabular result(s) of data to send to Benchling. Converted to list of dictionaries for each
row.
schema_id : str
ID should contain the Benchling schema ID to write to. This should be a string starting
with "assaysch_"
project_id : str
ID that results will be recorded against. This should be a string starting with "src_".
The members of your organization that have access to this project will also have
visibility to the results that this integration generates. You can find this ID by
right clicking on the Project that you have selected, and click on "Copy API ID".
If you don't see "Copy API ID" as an option, click on your avatar, click Settings,
and scroll to the bottom and verify that
"Enable Copy API ID button" is checked.
replace_special_characters : bool
Replace special characters in column names with underscores to mimic Benchling behavior.
Default is True.
ignore_na : bool
If True, drop columns with only nulls prior to upload. Default is True.
error_on_empty_result : bool
If True, raise an error if the DataFrame is empty. Default is True.
**kwargs
Keyword args to pass to create_assay_result_from_dict
drop_na (bool | None)
Returns
list[AssayResultCreate]
List of AssayResultCreate's to be uploaded to Benchling
function
create_assay_result_from_dict
Set up AssayResultCreate from dictionary
Parameters
result : dict
Dictionary of values to send to Benchling
schema_id : str
Benchling schema id
project_id : str
Benchling project id
drop_na : bool
Determine if you should remove na from benchling results dict
Returns
AssayResultCreate
Assay results to be uploaded to Benchling
function
create_custom_entity_obj
Create a custom entity object to create in Benchling
Parameters
entity_name : str
Name of the entity to create
folder_id : str
ID of the folder to create the entity in
input_schema_id : str
ID of the entity schema to use
registry_id : str
ID of the registry to use
fields : dict | None
Dictionary of fields to add to the entity
author_id : str | None
ID of the author to assign to the entity
naming_strategy : NamingStrategy
Naming strategy to use for the entity, by default NamingStrategy.NEW_IDS
Returns
entity_item : CustomEntityBulkCreate
Custom entity object to create in Benchling
function
create_custom_entities_bulk
Create custom entities in Benchling
Parameters
benchling_context : BenchlingContext
Benchling context object
custom_entities_objs : List
List of custom entity objects to create
custom_entity_service : CustomEntityService
Initiated custom entity service object
wait : bool
Whether to wait for the task to complete. Defaults to True.
error_on_fail : bool
Whether to raise an error if the task fails. Defaults to True.
Returns
custom_entity_task_ids : List
List of task ids for the custom entities created
function
update_custom_entities_bulk
Update custom entities in Benchling
Parameters
benchling_context : BenchlingContext
Benchling context object
custom_entities_objs : List
List of custom entity objects to update
custom_entity_service : CustomEntityService
Initiated custom entity service object
wait : bool
Whether to wait for the task to complete. Defaults to True.
error_on_fail : bool
Whether to raise an error if the task fails. Defaults to True.
Returns
custom_entity_ids : List
List of task ids for the custom entities updated
function
update_custom_entity_obj
Update a custom entity object to update in Benchling
Parameters
existing_entity : CustomEntity
Existing custom entity to update
folder_id : str | None
ID of the folder to move the custom entity to (if specified)
input_schema_id : str
ID of the entity schema to use
fields : dict | None
Dictionary of fields to add to the entity
author_id : str | None
ID of the author to assign to the entity
Returns
new_entity_param : CustomEntityBulkUpdate
Custom entity object to update in Benchling