allensdk.api.queries.rma_api module

class allensdk.api.queries.rma_api.RmaApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

See: RESTful Model Access (RMA)

ALL = 'all'
COUNT = 'count'
CRITERIA = 'rma::criteria'
DEBUG = 'debug'
EQ = '$eq'
EXCEPT = 'except'
EXCPT = 'excpt'
FALSE = 'false'
INCLUDE = 'rma::include'
IS = '$is'
MODEL = 'model::'
NUM_ROWS = 'num_rows'
ONLY = 'only'
OPTIONS = 'rma::options'
ORDER = 'order'
PIPE = 'pipe::'
PREVIEW = 'preview'
SERVICE = 'service::'
START_ROW = 'start_row'
TABULAR = 'tabular'
TRUE = 'true'
build_query_url(self, stage_clauses, fmt='json')[source]

Combine one or more RMA query stages into a single RMA query.

Parameters:
stage_clauses : list of strings

subqueries

fmt : string, optional

json (default), xml, or csv

Returns:
string

complete RMA url

build_schema_query(self, clazz=None, fmt='json')[source]

Build the URL that will fetch the data schema.

Parameters:
clazz : string, optional

Name of a specific class or None (default).

fmt : string, optional

json (default) or xml

Returns:
url : string

The constructed URL

Notes

If a class is specified, only the schema information for that class will be requested, otherwise the url requests the entire schema.

debug_clause(self, debug_value=None)[source]

Construct a debug clause for use in an rma::options clause. Parameters ———- debug_value : string or boolean

True, False, None (default) or ‘preview’
Returns:
clause : string

The query clause for inclusion in an RMA query URL.

Notes

True will request debugging information in the response. False will request no debugging information. None will return an empty clause. ‘preview’ will request debugging information without the query being run.

filter(self, key, value)[source]

serialize a single RMA query filter clause.

Parameters:
key : string

keys for narrowing a query.

value : string

value for narrowing a query.

Returns:
string

a single filter clause for an RMA query string.

filters(self, filters)[source]

serialize RMA query filter clauses.

Parameters:
filters : dict

keys and values for narrowing a query.

Returns:
string

filter clause for an RMA query string.

get_schema(self, clazz=None)[source]

Retrieve schema information.

model_query(self, *args, **kwargs)[source]

Construct and execute a model stage of an RMA query string.

Parameters:
model : string

The top level data type

filters : dict

key, value comparisons applied to the top-level model to narrow the results.

criteria : string

raw RMA criteria clause to choose what object are returned

include : string

raw RMA include clause to return associated objects

only : list of strings, optional

to be joined into an rma::options only filter to limit what data is returned

except : list of strings, optional

to be joined into an rma::options except filter to limit what data is returned

excpt : list of strings, optional

synonym for except parameter to avoid a reserved word conflict.

tabular : list of string, optional

return columns as a tabular data structure rather than a nested tree.

count : boolean, optional

False to skip the extra database count query.

debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional

how many database rows are returned (may not correspond directly to JSON tree structure)

start_row : int or string, optional

which database row is start of returned data (may not correspond directly to JSON tree structure)

Notes

See RMA Path Syntax for a brief overview of the normalized RMA syntax. Normalized RMA syntax differs from the legacy syntax used in much of the RMA documentation. Using the &debug=true option with an RMA URL will include debugging information in the response, including the normalized query.

model_stage(self, model, **kwargs)[source]

Construct a model stage of an RMA query string.

Parameters:
model : string

The top level data type

filters : dict

key, value comparisons applied to the top-level model to narrow the results.

criteria : string

raw RMA criteria clause to choose what object are returned

include : string

raw RMA include clause to return associated objects

only : list of strings, optional

to be joined into an rma::options only filter to limit what data is returned

except : list of strings, optional

to be joined into an rma::options except filter to limit what data is returned

tabular : list of string, optional

return columns as a tabular data structure rather than a nested tree.

count : boolean, optional

False to skip the extra database count query.

debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional

how many database rows are returned (may not correspond directly to JSON tree structure)

start_row : int or string, optional

which database row is start of returned data (may not correspond directly to JSON tree structure)

Notes

See RMA Path Syntax for a brief overview of the normalized RMA syntax. Normalized RMA syntax differs from the legacy syntax used in much of the RMA documentation. Using the &debug=true option with an RMA URL will include debugging information in the response, including the normalized query.

only_except_tabular_clause(self, filter_type, attribute_list)[source]

Construct a clause to filter which attributes are returned for use in an rma::options clause.

Parameters:
filter_type : string

‘only’, ‘except’, or ‘tabular’

attribute_list : list of strings

for example [‘acronym’, ‘products.name’, ‘structure.id’]

Returns:
clause : string

The query clause for inclusion in an RMA query URL.

Notes

The title of tabular columns can be set by adding ‘+as+<title>’ to the attribute. The tabular filter type requests a response that is row-oriented rather than a nested structure. Because of this, the tabular option can mask the lazy query behavior of an rma::include clause. The tabular option does not mask the inner-join behavior of an rma::include clause. The tabular filter is required for .csv format RMA requests.

options_clause(self, **kwargs)[source]

build rma:: options clause.

Parameters:
only : list of strings, optional
except : list of strings, optional
tabular : list of string, optional
count : boolean, optional
debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional
start_row : int or string, optional
order_clause(self, order_list=None)[source]

Construct a debug clause for use in an rma::options clause.

Parameters:
order_list : list of strings

for example [‘acronym’, ‘products.name+asc’, ‘structure.id+desc’]

Returns:
clause : string

The query clause for inclusion in an RMA query URL.

Notes

Optionally adding ‘+asc’ (default) or ‘+desc’ after an attribute will change the sort order.

pipe_stage(self, pipe_name, parameters)[source]

Connect model and service stages via their JSON responses.

Notes

See: Service Pipelines and Connected Services and Pipes

quote_string(self, the_string)[source]

Wrap a clause in single quotes.

Parameters:
the_string : string

a clause to be included in an rma query that needs to be quoted

Returns:
string

input wrapped in single quotes

service_query(self, *args, **kwargs)[source]

Construct and Execute a single-stage RMA query to send a request to a connected service.

Parameters:
service_name : string

Name of a documented connected service.

parameters : dict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

service_stage(self, service_name, parameters=None)[source]

Construct an RMA query fragment to send a request to a connected service.

Parameters:
service_name : string

Name of a documented connected service.

parameters : dict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

tuple_filters(self, filters)[source]

Construct an RMA filter clause.

Notes

See RMA Path Syntax - Square Brackets for Filters for additional documentation.