#DecipherAPI
Python client for Decipher data and survey list API.
git clone git@github.com:InContextSolutions/Decipher.git
cd Decipher
pip install .
pip install DecipherAPI
Creating a client requires your decipher username and password.
from DecipherAPI.client import Client
c = Client('you@example.org', 'Pa$$w0rd123')
By default, the client refers to the v2.decipherinc.com/api
host. Alternate hosts can be specified in the constructor:
c = Client('you@example.org', 'Pa$$w0rd123', host='custom.decipherinc.com/api')
All hosts are assumed to be over SSL (https
).
You can retrieve a list of all surveys in three formats:
json
: JavaScript Object Notationcsv
: comma-separated valuestsv
: tab-separated values
c.list_surveys(fmt='json')
c.get_survey(survey, start=None, end=None, status=None, columns=None, filters=None, fmt='json')
survey
is the full survey pathstart
andend
are Python datetimes (assumes UTC)columns
is a list of column names to include in the resultsfilters
is a list of column-specific rules- As above,
fmt
is the return format and can bejson
,csv
, ortsv
Included with the installation is a command-line utlity called decipher
with built-in help:
$ decipher --help
usage: decipher [-h] -U USERNAME -P PASSWORD [-H HOST] {pull,list} ...
A command-line utility for interacting with the Decipher API. Help is
available on subcommands (e.g. `decipher pull --help`)
optional arguments:
-h, --help show this help message and exit
-U USERNAME, --username USERNAME
user identification
-P PASSWORD, --password PASSWORD
user password
-H HOST, --host HOST host
valid subcommands:
{pull,list}
pull pull survey data
list list surveys
$ decipher pull --help
usage: decipher pull [-h] -s SURVEY [-t START] [-T END]
[-S {all,partial,complete,qualified,terminated,overquota}]
[-c COLUMNS] [-F FILTERS] [-f {json,tsv,csv}]
optional arguments:
-h, --help show this help message and exit
-s SURVEY, --survey SURVEY
survey name
-t START, --start START
utc start time: YYYY-MM-DDTHH:MM:SS.mmmmmm
-T END, --end END utc end time: YYYY-MM-DDTHH:MM:SS.mmmmmm
-S {all,partial,complete,qualified,terminated,overquota}, --status {all,partial,complete,qualified,terminated,overquota}
survey status
-c COLUMNS, --columns COLUMNS
columns
-F FILTERS, --filters FILTERS
filter conditions
-f {json,tsv,csv}, --fmt {json,tsv,csv}
return format
Example:
$ decipher -U dataapi -P dataapi pull -s 'kbdemo/data' -f csv -S qualified -c uuid,q1 -F 'q1=2'
$ decipher list --help
usage: decipher list [-h] [-f {json,tsv,csv}]
optional arguments:
-h, --help show this help message and exit
-f {json,tsv,csv}, --fmt {json,tsv,csv}
return format
Example:
$ decipher -U dataapi -P dataapi list -f csv