Skip to main content

Create and manage Google Forms from JSON using the official Google Forms API.

Project description

gformlib

PyPI version Python versions CI Documentation Status License: MIT codecov

gformlib is a Python library for creating and managing Google Forms programmatically from JSON configurations. It is a high-level wrapper around the official Google Forms API v1.

Features

  • Create Google Forms from a simple Python dict / JSON file
  • All question types supported: short answer, paragraph, multiple choice, checkboxes, dropdown, scale, date, time, file upload
  • Service-account and OAuth 2.0 authentication
  • Full type annotations (PEP 561 compliant)
  • Retrieve form responses with automatic pagination
  • Professional project structure, ready to publish to PyPI

Installation

pip install gformlib

Quickstart

1. Authenticate with a Service Account (recommended for servers)

from gformlib import GoogleFormsClient

client = GoogleFormsClient.from_service_account("path/to/service_account.json")

2. Authenticate with OAuth 2.0 (desktop / installed apps)

client = GoogleFormsClient.from_oauth_credentials(
    "client_secrets.json",
    token_file="token.json",
)

3. Create a form from a dict

info = client.create_form(
    {
        "title": "Customer Satisfaction Survey",
        "description": "Tell us how we're doing.",
        "questions": [
            {
                "title": "Your name",
                "type": "short_answer",
                "required": True,
            },
            {
                "title": "Overall rating",
                "type": "scale",
                "low": 1,
                "high": 5,
                "low_label": "Poor",
                "high_label": "Excellent",
                "required": True,
            },
            {
                "title": "Which features do you use?",
                "type": "checkboxes",
                "options": ["Dashboard", "Reports", "API", "Integrations"],
            },
            {
                "title": "Any other comments?",
                "type": "paragraph",
            },
        ],
    }
)

print(f"Form ID   : {info.form_id}")
print(f"Share URL : {info.responder_uri}")

4. Read responses

responses = client.list_responses(info.form_id)
for r in responses:
    print(r["responseId"], r.get("answers"))

Supported question types

type value Google Forms equivalent
short_answer Short answer (single line)
paragraph Paragraph (multi-line)
multiple_choice Multiple choice (radio)
checkboxes Checkboxes
dropdown Dropdown
scale Linear scale
date Date
time Time
file_upload File upload

Authentication setup

Service Account

  1. Create a Service Account in Google Cloud Console.
  2. Enable the Google Forms API and Google Drive API.
  3. Download the JSON key file.
  4. Share the target Google Drive folder with the service account email.

OAuth 2.0

  1. Create an OAuth 2.0 Desktop app client in Google Cloud Console.
  2. Download client_secrets.json.
  3. On first run, a browser window opens to authorise access.
  4. The token is cached in token.json for subsequent runs.

Development

git clone https://github.com/andhit-r/gformlib.git
cd gformlib
pip install -e ".[dev]"
pytest

Running the full test matrix with tox

tox

Contributing

See CONTRIBUTING.md.

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

gformlib-0.2.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

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

gformlib-0.2.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file gformlib-0.2.0.tar.gz.

File metadata

  • Download URL: gformlib-0.2.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gformlib-0.2.0.tar.gz
Algorithm Hash digest
SHA256 42510f7f1b5a9c4f72be10f716bf9c865f4f360ad6834f2ffd16f1a5d902f864
MD5 c2182d19f120458835e92a8812118824
BLAKE2b-256 a4b2585faffd9cd867800e5fa5f72abd735d1306ad0bc0597e95225e4145068c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gformlib-0.2.0.tar.gz:

Publisher: publish.yml on andhit-r/gformlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gformlib-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gformlib-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gformlib-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47359030caba0ba085e8016c8378aa12c6bbf5ff81a995686a38a9dea1423946
MD5 cefd68dfec1f36ed91de71513d7a6954
BLAKE2b-256 1a31609580314b6ff7f9714817a36ca4c0943c1e5b0a7ff5fc9101b0cf563746

See more details on using hashes here.

Provenance

The following attestation bundles were made for gformlib-0.2.0-py3-none-any.whl:

Publisher: publish.yml on andhit-r/gformlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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