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.0.tar.gz (22.7 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.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: surveyjs-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 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.0.tar.gz
Algorithm Hash digest
SHA256 aa95376fd9196826d1270d83be7b1a0d43ab70552010aca21ca96bd4de38faed
MD5 e7ff4dc728302172d5f87af41165fb60
BLAKE2b-256 08cd1712fb9d10acbfd29a4654db93e9a68192f134a7393f2872f15f18dfa5e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: surveyjs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58a4a762fda6043386ba10756a40bf359ce30fd7621c5335957ee9df826cdb52
MD5 ed8fb96690644c121301ab0b52296826
BLAKE2b-256 f4cece8078618a3c308c226faad9123d25645ea63fe1ddefddde4bda7f783add

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