Skip to main content

SurveyJS (JSON data) API for Python

Project description

surveyjs (Python)

SurveyJS (JSON Form Builder) data API for Python.

For information about the SurveyJS project, see https://surveyjs.io

Introduction

surveyjs is a Python package which loads and transforms SurveyJS Creator JSON (survey schema) and Form JSON (submission data) into usable Python objects.

Its main aim is to provide easy access to a SurveyJS Form's questions (fields, layout elements, etc.) also captured as Python objects, which makes this API very versatile and usable.

Notes about terms:

  • SurveyCreator: The Survey Creator (form builder) schema which is the design of a Form.
  • SurveyForm: A filled-in Survey Form, aka Form response, submission.
  • Question: Input (field) and layout elements in SurveyJS (Creator and Form). Question is not a semantic term for a layout element (e.g. panel), but we follow the SurveyJS convention of calling all components "questions".

Question types: Source code (file prefix question): https://github.com/surveyjs/survey-library/tree/master/packages/survey-core/src

Features

  • Compatible with Python 3.8 and later
  • Constructor of the SurveyCreator and SurveyForm class only requires the JSON (string or dict).
  • Get a SurveyForm object's Questions as usable Python objects e.g. datetime, boolean, list (for checkbox), dict (for matrix) etc.
  • Support for all SurveyJS question types
  • Open source (MIT License)

Installation

pip install surveyjs

Source Install

git clone <repo-url>
cd python-surveyjs
pip install -e .

Usage Examples

from surveyjs import SurveyCreator, SurveyForm

# survey_json is a SurveyJS Creator JSON schema (string or dict)
# form_json is a SurveyJS Form submission JSON (string or dict)

creator = SurveyCreator(survey_json)
form = SurveyForm(form_json, creator)

# Text question
print(form.input_questions['firstName'].label)
# 'First Name'

print(form.input_questions['firstName'].value)
# 'Bob'

# Checkbox question
print(form.input_questions['colors'].value)
# ['red', 'blue']

# Rating question
print(form.input_questions['satisfaction'].value)
# 4

# Boolean question
print(form.input_questions['agree'].value)
# True

# Matrix question
print(form.input_questions['quality'].value)
# {'affordable': 'good', 'does-what-it-claims': 'excellent'}

# Access by attribute
print(form.data.firstName.value)
# 'Bob'

Unit Tests

Run all tests

From toplevel directory:

poetry run python -m unittest

Run specific (questions) unittests

All questions, from toplevel directory:

poetry run python -m unittest tests/test_question_*.py

Nested questions (complexity), from toplevel directory:

poetry run python -m unittest tests/test_nested_questions.py

Run specific component unittest

poetry run python -m unittest tests.test_question_ranking.TestQuestionRanking.test_choices

License

MIT

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

surveyjs-0.1.1.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

surveyjs-0.1.1-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file surveyjs-0.1.1.tar.gz.

File metadata

  • Download URL: surveyjs-0.1.1.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Darwin/24.6.0

File hashes

Hashes for surveyjs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eba2d6a1687535173af17135ee59bcb9876dc72bd99458269f1ef92238d4c3d6
MD5 ddf48499f09bcce247d0c168a7a97538
BLAKE2b-256 164e576ca9c7abd95bb8eb7a79b1c7649d4c8fcb5629ba76fd2e432403920eb2

See more details on using hashes here.

File details

Details for the file surveyjs-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: surveyjs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Darwin/24.6.0

File hashes

Hashes for surveyjs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8630eba7f8e89efa11542566c0a7e559d2dfef2e26bd1198e30028a0acea7b5d
MD5 0a49927183502ef26640bd3bf71d0d14
BLAKE2b-256 11c830f0ccd235f86c3d160e9a6869b8312c5b20e7f2d33cff708dbce19a3e46

See more details on using hashes here.

Supported by

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