# Tally Python client
The Tally Python client is a wrapper for [Datasmoothie's Tally API](https://tally.datasmoothie.com) for market research and survey data. Tally is a RESTful
API that leverages Quantipy and other techologies to give users access to all the data processing, aggregation and
exporting functions they need.

Those who want to use python to communicate with Tally can both use the traditional
`requests` library, or they can use this wrapper for convenience.

# Installation
```pip isntall datasmoothie-tally-client```

The Tally client is compatible with all versions of Python 3.

# Quick start
Tally is compatible with both SPSS (.sav) files and Quantipy files.

```
import tally

ds = tally.DataSet(api_token=[your_token])
ds.use_spss('my_spss_file.sav')

pandas_dataframe = ds.crosstab(x=['q1', 'q2'], y=['gender'], ['locality'], sig_level=[0.05])

ds.build_powerpoint(filename='my_powerpoint.pptx',
                    powerpoint_template='My_Branded_Template.pptx', 
                    x=['q1', 'q2', 'q3'], 
                    y=['gender', 'locality']
                    )

ds.build_excel(filename='my_tables.xlsx',
               powerpoint_template='My_Branded_Template.pptx', 
               x=['q1', 'q2', 'q3'], 
               y=['gender', 'locality'],
               sig_level[0.05,  0.1]
               )

```
## Supported file formats and data sources
Tally supports SPSS fiels, Quantipy files. It also supports external datasources, such as Datasmoothie (with more on the way).

```
#datasmoothie (remote storage of data)
ds.use_datasmoothie(datasmoothie_token=[my_datasmoothie_api_token])

#datasmoothie (remote storage of data)
ds.use_confirmit(confirmit_credentials)

#using spss (local sav file)
ds.use_spss(path_to_sav_file)

#using csv (local CSV file, i.e. generated by Excel)
ds.use_csv(path_to_csv_file)

#using quantipy (local json and csv files)
ds.use_quantipy(path_to_json_metadata, path_to_csv_data)
```


# Developing the Tally Python client

## Gitpod
Click the button to get started developing the wrapper with GitPod:

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/datasmoothie/tally-client/)

Once you are up and running in GitPod, the tests can be run with 

```python -m pytest --token=[my_token]```

In this case the tests will run against the live Tally server, which will count against your API calls quota. 

Or if you have a development server of Tally running, use

```python -m pytest --api_url=[url_for_tally] --token=[my_token]```

### Developing the wrapper

We use pytest to test. Example pytest commands are

Run all tests
```python -m pytest --token=[your_token]```

Run all tests for SPSS files
```python -m pytest -k spss --token=[your_token]```

Run test called `test_spss_crosstab`
```python -m pytest -k test_spss_crosstab --token=[your_token]```

The `-k` parameter for pytest uses the supplied argument as a keyword and runs all tests that match the string. 