Retrieving All Study Names from Labkey Using Python API

LabKey Support Forum (Inactive)
Retrieving All Study Names from Labkey Using Python API cmwest3  2017-11-02 14:41
Status: Closed
 
Hello,

We've previously been using the HTTP Interface using the following URI to retrieve all the study names residing on a server: localhost/labkey/query/home/selectRows.api?query.queryName=Containers&schemaName=core&query.containerFilterName=AllFolders&query.Parent%2FDisplayName~isblank

We've been trying to use the Python API to construct a similar request but have run into some issues.

After reviewing the Python API source code, query.py, for the QueryFilter object on GitHub, the `get_url_parameter_name` function will always place a '~' character within the query string and not allow us to form the query string 'query.containerFilterName=AllFolders'. Additionally, there is no filter_type that clearly represent 'isblank' and so we've been attempting to create a QueryFilter by calling QueryFilter('Parent%2FDisplayName', '', 'eq') (Notice the two single quotes in the second parameter). Unfortunately, this method is only returning the single 'home' study which isn't what we're looking for.

Seeing as it is difficult to replicate the URI of the HTTP Interface with the Python interface, how can we go about making QueryFilter(s) that would return all study names on a server?

Thank you,
Cameron West
 
 
Jon (LabKey DevOps) responded:  2017-11-03 17:08
Hi Cameron,

You wouldn't use query.containerFilterName, you'd use container_filter instead.

If you access the Schema Browser and do the following:

1. Select Core for the Schema
2. Select Containers for the Query
3. Click View Data to see the grid
4. Click the Grid button and select Folder Filter > All Folders
5. Click the Export button and click the Scripts tab
6. Select Python and click Create Script.

You should end up with something like this:

# This script targets the client api version 0.4.0 and later
import labkey

# This script targets the client api version 0.4.0 and later
import labkey

server_context = labkey.utils.create_server_context('localhost', 'home', 'labkey', use_ssl=False)

my_results = labkey.query.select_rows(
    server_context=server_context,
    schema_name='core',
    query_name='Containers',
    container_filter='AllFolders'
)

That same container_filter is referenced in line 90 of the query.py code:

https://github.com/LabKey/labkey-api-python/blob/master/labkey/query.py#L90

If you choose to use the filter "isBlank" on the Parent column, then your query will look like this if you export it:

# This script targets the client api version 0.4.0 and later
import labkey

server_context = labkey.utils.create_server_context('localhost', 'home', 'labkey', use_ssl=False)

my_results = labkey.query.select_rows(
    server_context=server_context,
    schema_name='core',
    query_name='Containers',
    filter_array=[
        labkey.query.QueryFilter('Parent/DisplayName', '', 'isblank')
    ],
    container_filter='AllFolders'
)

Does this make sense?

Regards,

Jon