Python-api client
Python-api client
The MOLGENIS python client API allows you to retrieve, create, update and delete entities from within python.
You can install the Python REST Client as a package with pip
:
Now you can create a python script. To get started, you should import the Python client, connect to a molgenis server and login:
Always put the import and molgenis.Session in your script to make the api work.
Overview example
To get a full overview of all functions in the python client, you can look at the examples on GitHub.
Methods
login
Login to the MOLGENIS REST API
Argument | Description | Required | Default |
---|---|---|---|
| Username for a registered molgenis user | yes | |
| Password for the user | yes |
logout
Logout from the MOLGENIS REST API and destroy the session.
##get_by_id
Retrieves a single entity row from an entity repository.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| The value for the idAttribute of the entity | yes | |
| The list of attributes to retrieve | no | All attributes |
| The attributes to expand | no | None |
##get
Retrieves entities and returns the result in a dataframe.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| Query string in rsql/fiql format (see below) | no | None |
| The index of the first row to retrieve (zero indexed) | no | 0 |
| The maximum number of rows to return (max 10000) | no | 100 |
| The list of attributes to retrieve | no | All attributes |
| attributeName of the column to sort on | no | None |
| The order to sort in | no | None |
Supported RSQL/FIQL query operators (see https://github.com/jirutka/rsql-parser)
Operator | Symbol |
---|---|
Logical AND |
|
Logical OR |
|
Group |
|
Equal to |
|
Less then |
|
Less then or equal to |
|
Greater than |
|
Greater tha or equal to |
|
Argument can be a single value, or multiple values in parenthesis separated by comma. Value that doesn’t contain any reserved character or a white space can be unquoted, other arguments must be enclosed in single or double quotes.
Examples
add
Creates a new instance of an entity (i.e. a new row of the entity data table) and returns the id.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| Dictionary containing file attribute values for the entity row. The dictionary should for each file attribute map the attribute name to a tuple Containing the file name and an input stream. | no | Empty dictionary |
| Dictionary mapping attribute name to non-file attribute value for the entity row, gets merged with the kwargs argument | no | Empty dictionary |
| Keyword arguments get merged with the data argument | no |
Examples
update_one
Updates a value of a specified attribute in a specified row in a specified entityType.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| The value for the idAttribute of the entity | yes | |
| Attribute to update | yes | |
| New value of the attribute | yes |
add_all
Creates new instances of an entity (i.e. adds new rows to the entity data table) and returns the ids.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| List of dictionaries with the attributes of the entities | yes |
Example
delete
Deletes row based on its id.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| Id of the entity that should be deleted | yes |
delete_list
Deletes a number of rows based on a list of id's.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| List of id's of entities that should be deleted | yes |
upload_zip
This function uploads a zip file based on the EMX format.
Argument | Description | Required | Default |
---|---|---|---|
| A zip file containing an attribute, entities, packages file (tsv/csv) to specify the meta data and optionally data defined in the meta data files | yes |
get_entity_meta_data
Retrieves the metadata for an entity repository.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes |
get_attribute_meta_data
Retrieves the metadata for a single attribute of an entity repository.
Argument | Description | Required | Default |
---|---|---|---|
| Fully qualified name of the entity | yes | |
| Name of the attribute | yes |
Last updated