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.1.1.tar.gz (24.6 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.1.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gformlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 771acf71ea4c7ab034ec53d44dc90d2a7f20ebb1870ba98cd1f24fd7bc343647
MD5 381199bbdfdac2029e4263f5a37be66c
BLAKE2b-256 e4ad3b6339b890d13631867fee2e6705d1a139fa8310d2226d75d2d1293dea4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gformlib-0.1.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: gformlib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36f937ab2310df121e9f898387064def5b61a62bcd0138e4d322493c1780c276
MD5 70560c36bcfa3bda5dc86bc57f6e9a09
BLAKE2b-256 a27623ce88945df29b186c4d4ef0df5f162c4b5911f6ff24a59150546d27250c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gformlib-0.1.1-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