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.
- 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
pip install gformlibfrom gformlib import GoogleFormsClient
client = GoogleFormsClient.from_service_account("path/to/service_account.json")client = GoogleFormsClient.from_oauth_credentials(
"client_secrets.json",
token_file="token.json",
)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}")responses = client.list_responses(info.form_id)
for r in responses:
print(r["responseId"], r.get("answers"))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 |
- 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.
- 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.
git clone https://github.com/andhit-r/gformlib.git
cd gformlib
pip install -e ".[dev]"
pytesttoxSee CONTRIBUTING.md.