Skip to main content

Utilities for qualtrics surveys.

Project description

qualtrics-utils

Utilities for qualtrics surveys. Get and sync survey responses, generate codebooks, & c.

Quickstart 🚀

This project requires Python ^3.10 to run.

via poetry

Install poetry, then run

poetry install

And you're done.

surveys

Exporting

Example (get a survey's responses, convert to a pandas DataFrame):

from qualtrics_utils import Surveys

surveys = Surveys(api_token=QUALTRICS_API_TOKEN)

exported_file = surveys.get_responses_df(
    survey_id=SURVEY_ID
)
df = exported_file.data

Survey's can be exported to a variety of formats, including:

  • .csv
  • .xlsx
  • .json

And with a variety of parameters. Please see the ExportCreationRequest documentation herein

sync

Perhaps one of the more useful features hereof is the ability to sync survey responses to the following services:

  • Google Sheets
  • MySQL

Future services will include:

  • PostgreSQL
  • MongoDB
  • AWS S3

Syncing can either be leveraged as a standard python module, or as a CLI tool.

CLI

Execute the help command to see the available options:

python -m qualtrics_utils.sync --help

See also the config.example.toml for an example configuration file.

Module

Simply import sync_* from the qualtrics_utils.sync module, and execute the function with the appropriate arguments.

Syncing information

The process is fairly straightforward:

  1. Ensure that the service has two "tables", or datastores for:
    • Survey responses: This defaults to the input base name (defaults to the survey ID) + _responses
    • Survey export statuses: This defaults to the input base name (defaults to the survey ID) + _status
  2. Export the survey responses to the service
  3. Update the survey export statuses to reflect the export

This will allow for a sync to pick up where it left off, only exporting newly found responses. Please note, if a first time sync contains enough survey responses to exceed the service's limits (~1.8 GB), the sync will fail. Please see the Qualtrics documentation for more information.

For example, in google sheets:

from qualtrics_utils import Surveys, sync_sheets
import pandas as pd

# Survey ID or URL
survey_id = ...
# Sheet URL
responses_url = ...

# dict of extra survey arguments for the export creation request
survey_args = ...

sheets = Sheets()

def post_processing_func(df: pd.DataFrame) -> pd.DataFrame:
    # Do some post processing of the responses before syncing here
    return df

sync_sheets(
    survey_id=survey_id,
    surveys=surveys,
    response_post_processing_func=post_processing_func,
    sheet_name=table_name,
    sheet_url=responses_url,
    sheets=sheets,
    **survey_args,
)

Codebook mapping

generate.py

Takes the exported .qsf file from Qualtrics and generates a codebook mapping question IDs to question text and answer choices. The output is a JSON file containing a list of dictionaries.

Example row:

{
        "question_number": "Q5.10",
        "question_string": "What is your role at this school?",
        "answer_choices": "..."
},

map_columns.py

Takes a codebook mapping (generated by the above function) and creates conditional statements to map the question columns into valid Tableau or SQL code. Used to create a singular question column in the above formats when there are multiple questions in a single question block (e.g. multiple Likert scale questions).

OpenAPI client

To handle the majority of the qualtrics API calls, we use the publicly available OpenAPI spec, found on the qualtrics API docs website

The OpenAPI spec is fed to openapi-python-client, where it's used to generate a python client(s) for the qualtrics API. These clients (for each of the utilized APIs) come bundled and pre-generated as-is, but to create them anew, one can execute the create_api_client.py script. This will re-generate the clients and place them in the qualtrics_utils directory. Occasionally, the OpenAPI spec is broken and mis-validated from Qualtrics; regenerate at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qualtrics_utils-0.6.5.tar.gz (101.6 kB view details)

Uploaded Source

Built Distribution

qualtrics_utils-0.6.5-py3-none-any.whl (129.2 kB view details)

Uploaded Python 3

File details

Details for the file qualtrics_utils-0.6.5.tar.gz.

File metadata

  • Download URL: qualtrics_utils-0.6.5.tar.gz
  • Upload date:
  • Size: 101.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for qualtrics_utils-0.6.5.tar.gz
Algorithm Hash digest
SHA256 edfcd08355d315350ed1c72bd39e2bce50da7d6c60431c4be5aa070103d1a393
MD5 39a9a38083c062e229652b275634f46e
BLAKE2b-256 bba95bc7eca3a02c93436ad2f085bae95dc17c84340473cf2e1d32435b655ae8

See more details on using hashes here.

File details

Details for the file qualtrics_utils-0.6.5-py3-none-any.whl.

File metadata

  • Download URL: qualtrics_utils-0.6.5-py3-none-any.whl
  • Upload date:
  • Size: 129.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Darwin/23.3.0

File hashes

Hashes for qualtrics_utils-0.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 970ef2f9c06e310d746cf8ca1e0dd7e7b73470a143ddff87e74fcad40307c8cf
MD5 aa148b9278a76febd7710611a6b423b3
BLAKE2b-256 9644ac11851e688e0b1f3e5c292e575cbb8811a163c80b8397f19d1c4a838328

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page