Running the Code Directly
You can use the code directly from the command line or the python interpreter, without going through the http API.
The examples given here assume you are using the sample data provided by the protari-sample
package.
Running from the Command Line
You can run a single sample query directly from the command line.
The essential imports and commands are provided in the file scripts/example.py
,
which you can run directly from the linux command line via python scripts/example.py
.
You need to supply two arguments - the path to the settings file, and the path to the dataset_config directory
The script randomly chooses a dataset and some fields from those available and returns the result, eg:
$ python scripts/example.py ./settings_example.yaml ../protari-sample/dataset_config
>>> dataset_config_dict['sample'].run_query_class(group_bys=['COUNTRY'], conditions=['SEX=F'])
Rows: {"fields": [{"type": "integer", "name": "COUNTRY", "title": "Country of Birth"},
{"calculated": true, "name": "perturbed count", "title": "perturbed count"}],
"values": [[1101, 39], [1102, 0], [1199, 0],
[1201, 6], [1301, 0], [1302, 0],
[1303, 6],[1304, 0], [9999, 0]],
"query": {
"function": [{"type": "count"}],
"group_by": [{"name": "COUNTRY"}],
"where": [{"values": ["F"], "name": "SEX"}]
}
}
Running from Python
You have more flexibility to run your own queries from the python interpreter. Check out the example script above, along with the tests, to get started.