allensdk.api.queries.rma_api module

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

Bases: 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(stage_clauses, fmt='json')[source]

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

Parameters:
stage_clauseslist of strings

subqueries

fmtstring, optional

json (default), xml, or csv

Returns:
string

complete RMA url

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

Build the URL that will fetch the data schema.

Parameters:
clazzstring, optional

Name of a specific class or None (default).

fmtstring, optional

json (default) or xml

Returns:
urlstring

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(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:
clausestring

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(key, value)[source]

serialize a single RMA query filter clause.

Parameters:
keystring

keys for narrowing a query.

valuestring

value for narrowing a query.

Returns:
string

a single filter clause for an RMA query string.

filters(filters)[source]

serialize RMA query filter clauses.

Parameters:
filtersdict

keys and values for narrowing a query.

Returns:
string

filter clause for an RMA query string.

get_schema(clazz=None)[source]

Retrieve schema information.

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

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

Parameters:
modelstring

The top level data type

filtersdict

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

criteriastring

raw RMA criteria clause to choose what object are returned

includestring

raw RMA include clause to return associated objects

onlylist of strings, optional

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

exceptlist of strings, optional

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

excptlist of strings, optional

synonym for except parameter to avoid a reserved word conflict.

tabularlist of string, optional

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

countboolean, optional

False to skip the extra database count query.

debugstring, optional

‘true’, ‘false’ or ‘preview’

num_rowsint or string, optional

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

start_rowint 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(model, **kwargs)[source]

Construct a model stage of an RMA query string.

Parameters:
modelstring

The top level data type

filtersdict

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

criteriastring

raw RMA criteria clause to choose what object are returned

includestring

raw RMA include clause to return associated objects

onlylist of strings, optional

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

exceptlist of strings, optional

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

tabularlist of string, optional

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

countboolean, optional

False to skip the extra database count query.

debugstring, optional

‘true’, ‘false’ or ‘preview’

num_rowsint or string, optional

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

start_rowint 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(filter_type, attribute_list)[source]

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

Parameters:
filter_typestring

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

attribute_listlist of strings

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

Returns:
clausestring

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(**kwargs)[source]

build rma:: options clause.

Parameters:
onlylist of strings, optional
exceptlist of strings, optional
tabularlist of string, optional
countboolean, optional
debugstring, optional

‘true’, ‘false’ or ‘preview’

num_rowsint or string, optional
start_rowint or string, optional
order_clause(order_list=None)[source]

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

Parameters:
order_listlist of strings

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

Returns:
clausestring

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(pipe_name, parameters)[source]

Connect model and service stages via their JSON responses.

Notes

See: Service Pipelines and Connected Services and Pipes

quote_string(the_string)[source]

Wrap a clause in single quotes.

Parameters:
the_stringstring

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

Returns:
string

input wrapped in single quotes

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

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

Parameters:
service_namestring

Name of a documented connected service.

parametersdict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

service_stage(service_name, parameters=None)[source]

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

Parameters:
service_namestring

Name of a documented connected service.

parametersdict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

tuple_filters(filters)[source]

Construct an RMA filter clause.

Notes

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