Flexilims is a laboratory database software written and maintained by the database team of the Crick. Flexilims web interface can be accessed at https://flexylims.thecrick.org/flexilims/. Mike Gavrielides wrote an API. The documentation is here https://flexylims.thecrick.org/flexilims/api/docs. This repository is defining python wrappers to use the API.
This package contains a class with generic wrapper to the flexilims get/put/post request. It should not depend on particular local schema.
Data is sent via http requests containing a json-formatted body. All valid json should work, with some caveat for empty structures.
Most basic datatype work as expected. This includes:
strincluding empty strings.- Numbers,
intorfloat. listcontaining at least one element.dictcontaining at least one element.- Nested structures of the above.
Some types can be uploaded but will converted when uploaded to the database, and come
back as a different type when using a get request.
- A
tuplebecomes alist. - Empty
dictare uploaded asnull. - Empty
listare uploaded asnull.
Warning: the reply from flexilims after a post request is sent before uploading the
database, empty list and dictionaries are still present as such in this reply.
Trying to upload these types will raise an error.
complexset/frozensetbytesrange- Almost any other non built-in types (
np.array,pd.DataFrame...)
To connect to flexilims you must be on the Crick network (or vpn to it). Your flexilims username and password can be used to get a token than must then be provided in the headers of any subsequent request.
The simplest way to do that is to create a Flexilims object that will handle the authentication. It can also have a default project to avoid re-entering the id at every request.
import flexilims.main as flm
session = flm.Flexilims(username='MyUserName', password='Password', project_id='hexcode000000000')
The session can then be use to get data of any type:
# Get request:
results = session.get(datatype='mouse')
results will be a list of dictionary with each element being one mouse in that case.
You can specify the project_id in the call to get if you didn't set it at session
creation (or if you want to access a different project for this request). It is possible
to query a selection of the datatype, see docstring for documentation.
The database is hierarchical, each entity has an origin. The list of children from one entity can get obtained using get_children:
# Get the database entries for all children of one entity
children = session.get_children(id='hexcode000000000')
New entries can be created with the post request. Once again, it's a simple call of a session method:
now = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
session.post(datatype='mouse', name='test_ran_on_%s' % now, attributes=dict(age=12))
The parent of the entity can be specified using the origin_id keyword. See docstring for more information.
Similarly one can update existing elements. You can update one entry using update_one:
rep = session.update_one(id=entity_id, datatype='recording', strict_validation=False)
Entities can only be identify by hexadecimal id. Name, origin_id or attributes can be changed. See docstring for more details
You can also update multiple entries all at once:
rep = session.update_many(datatype='session', update_key='test_attribute', update_value='new_value')
This should print something like:
'updated successfully 5 items of type session with test_attribute=new_value'
That's obviously dangerous as you rarely want to have the same new_value for everyone. You can select which element to update by using the query_key/query_value pair but that can query only attributes.
rep = session.update_many(datatype='session', query_key='test_uniq', query_value='unique',
update_key='test_uniq', update_value='unique')
Other request are provided:
Returns all children from an entity
List existing projects and their attributes
Tests require flexiznam to get the password.