Create and manage Google Forms from JSON using the official Google Forms API.
Project description
gformlib
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
- Create a Service Account in Google Cloud Console.
- Enable the Google Forms API and Google Drive API.
- Download the JSON key file.
- Share the target Google Drive folder with the service account email.
OAuth 2.0
- Create an OAuth 2.0 Desktop app client in Google Cloud Console.
- Download
client_secrets.json. - On first run, a browser window opens to authorise access.
- The token is cached in
token.jsonfor 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42510f7f1b5a9c4f72be10f716bf9c865f4f360ad6834f2ffd16f1a5d902f864
|
|
| MD5 |
c2182d19f120458835e92a8812118824
|
|
| BLAKE2b-256 |
a4b2585faffd9cd867800e5fa5f72abd735d1306ad0bc0597e95225e4145068c
|
Provenance
The following attestation bundles were made for gformlib-0.2.0.tar.gz:
Publisher:
publish.yml on andhit-r/gformlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gformlib-0.2.0.tar.gz -
Subject digest:
42510f7f1b5a9c4f72be10f716bf9c865f4f360ad6834f2ffd16f1a5d902f864 - Sigstore transparency entry: 1615095118
- Sigstore integration time:
-
Permalink:
andhit-r/gformlib@2ec61815e26f004bf71a902e82aae372d97074ec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/andhit-r
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2ec61815e26f004bf71a902e82aae372d97074ec -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47359030caba0ba085e8016c8378aa12c6bbf5ff81a995686a38a9dea1423946
|
|
| MD5 |
cefd68dfec1f36ed91de71513d7a6954
|
|
| BLAKE2b-256 |
1a31609580314b6ff7f9714817a36ca4c0943c1e5b0a7ff5fc9101b0cf563746
|
Provenance
The following attestation bundles were made for gformlib-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on andhit-r/gformlib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gformlib-0.2.0-py3-none-any.whl -
Subject digest:
47359030caba0ba085e8016c8378aa12c6bbf5ff81a995686a38a9dea1423946 - Sigstore transparency entry: 1615095128
- Sigstore integration time:
-
Permalink:
andhit-r/gformlib@2ec61815e26f004bf71a902e82aae372d97074ec -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/andhit-r
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2ec61815e26f004bf71a902e82aae372d97074ec -
Trigger Event:
push
-
Statement type: