Adding Users in Bulk
Last updated
Last updated
When Clarity LIMS is replacing an existing LIMS, or if the LDAP integration is not being utilized, a list of current LIMS users and collaborators often already exists in a file.
In this scenario, it is useful to use this file to create users in Clarity LIMS. This topic provides an example script and outlines a strategy for the bulk import of users from a simple CSV file.
The attached script parses a CSV file containing user information. Based on the columns of data present in the file, the script then creates users and their associated labs in Clarity LIMS.
Since this operation is independent of workflow and sample processing, the parameters used to invoke the script differ from those typically used:
An example of the full syntax to invoke the script is as follows:
File format
The format of the file is very flexible. The order of the columns is not relevant.
If the names of your columns do not match the column names in the example file, modify the script so that the column names match yours.
Attached to this topic, you'll find a CSV file containing test data that illustrates the format further. The structure of this file is shown below.
Notice that the first two rows do not contain data of interest, and so the script ignores them. This is controlled by line 38 of the script, which specifies the location of the header row:
The main method of interest is importData(). After parsing the file into data structures (COLS and DATA), the data is processed one line at a time using the following pseudocode:
To reduce the number of queries the script makes back to the server, each time a new lab is created it is added to the cache of existing labs that is stored in the LABS dictionary.
Finally, if you set the DEBUG variable to true, the script will stop processing the file after the first successful creation of a user. This is useful as it allows you to test your script using just one line of the CSV file at a time.
Both of the attached *.py script files are placed on the Clarity LIMS server, in the /opt/gls/clarity/customextensions folder.
The users will be created with the same hard-coded password (abcd1234). It is possible to have the script create a unique password for each user. If this is required, consider having the script e-mail the user with a 'welcome' e-mail outlining their username and password.
The users will be created with permissions to access the Collaborations Interface only. This can be modified as required.
The contents of the 'Institution' column will be used to associate the user with a 'Lab', if a value for this column is provided.
The example code provided is for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.
user_List_Test.csv:
userImport.py:
-h
The URI of the server to which you want to upload the users (Required)
-u
The username of a user with administrative privileges (Required)
-p
The password of the user (Required)
-f
The path to the CSV file containing the user-related data (Required)