gformlib 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gformlib-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Andhitia Rama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.4
2
+ Name: gformlib
3
+ Version: 0.1.1
4
+ Summary: Create and manage Google Forms from JSON using the official Google Forms API.
5
+ Author-email: Andhitia Rama <andhitia.r@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Andhitia Rama
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/andhit-r/gformlib
29
+ Project-URL: Documentation, https://gformlib.readthedocs.io
30
+ Project-URL: Repository, https://github.com/andhit-r/gformlib
31
+ Project-URL: Bug Tracker, https://github.com/andhit-r/gformlib/issues
32
+ Project-URL: Changelog, https://github.com/andhit-r/gformlib/blob/main/CHANGELOG.md
33
+ Keywords: google,forms,api,survey,automation
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Topic :: Internet :: WWW/HTTP
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Classifier: Typing :: Typed
45
+ Requires-Python: >=3.9
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: google-api-python-client>=2.100.0
49
+ Requires-Dist: google-auth>=2.23.0
50
+ Requires-Dist: google-auth-oauthlib>=1.1.0
51
+ Requires-Dist: google-auth-httplib2>=0.2.0
52
+ Provides-Extra: dev
53
+ Requires-Dist: pytest>=7.4; extra == "dev"
54
+ Requires-Dist: pytest-cov>=4.1; extra == "dev"
55
+ Requires-Dist: pytest-mock>=3.11; extra == "dev"
56
+ Requires-Dist: black>=23.0; extra == "dev"
57
+ Requires-Dist: isort>=5.12; extra == "dev"
58
+ Requires-Dist: mypy>=1.5; extra == "dev"
59
+ Requires-Dist: types-google-cloud-ndb; extra == "dev"
60
+ Requires-Dist: flake8>=6.1; extra == "dev"
61
+ Requires-Dist: tox>=4.11; extra == "dev"
62
+ Provides-Extra: docs
63
+ Requires-Dist: sphinx>=7.1; extra == "docs"
64
+ Requires-Dist: sphinx-rtd-theme>=1.3; extra == "docs"
65
+ Requires-Dist: sphinxcontrib-httpdomain>=1.8; extra == "docs"
66
+ Requires-Dist: myst-parser>=2.0; extra == "docs"
67
+ Dynamic: license-file
68
+
69
+ # gformlib
70
+
71
+ [![PyPI version](https://badge.fury.io/py/gformlib.svg)](https://pypi.org/project/gformlib/)
72
+ [![Python versions](https://img.shields.io/pypi/pyversions/gformlib.svg)](https://pypi.org/project/gformlib/)
73
+ [![CI](https://github.com/andhit-r/gformlib/actions/workflows/test.yml/badge.svg)](https://github.com/andhit-r/gformlib/actions/workflows/test.yml)
74
+ [![Documentation Status](https://readthedocs.org/projects/gformlib/badge/?version=latest)](https://gformlib.readthedocs.io/en/latest/)
75
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
76
+ [![codecov](https://codecov.io/gh/andhit-r/gformlib/branch/main/graph/badge.svg)](https://codecov.io/gh/andhit-r/gformlib)
77
+
78
+ **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](https://developers.google.com/forms/api/reference/rest).
79
+
80
+ ## Features
81
+
82
+ - Create Google Forms from a simple Python dict / JSON file
83
+ - All question types supported: short answer, paragraph, multiple choice, checkboxes, dropdown, scale, date, time, file upload
84
+ - Service-account and OAuth 2.0 authentication
85
+ - Full type annotations (PEP 561 compliant)
86
+ - Retrieve form responses with automatic pagination
87
+ - Professional project structure, ready to publish to PyPI
88
+
89
+ ## Installation
90
+
91
+ ```bash
92
+ pip install gformlib
93
+ ```
94
+
95
+ ## Quickstart
96
+
97
+ ### 1. Authenticate with a Service Account (recommended for servers)
98
+
99
+ ```python
100
+ from gformlib import GoogleFormsClient
101
+
102
+ client = GoogleFormsClient.from_service_account("path/to/service_account.json")
103
+ ```
104
+
105
+ ### 2. Authenticate with OAuth 2.0 (desktop / installed apps)
106
+
107
+ ```python
108
+ client = GoogleFormsClient.from_oauth_credentials(
109
+ "client_secrets.json",
110
+ token_file="token.json",
111
+ )
112
+ ```
113
+
114
+ ### 3. Create a form from a dict
115
+
116
+ ```python
117
+ info = client.create_form(
118
+ {
119
+ "title": "Customer Satisfaction Survey",
120
+ "description": "Tell us how we're doing.",
121
+ "questions": [
122
+ {
123
+ "title": "Your name",
124
+ "type": "short_answer",
125
+ "required": True,
126
+ },
127
+ {
128
+ "title": "Overall rating",
129
+ "type": "scale",
130
+ "low": 1,
131
+ "high": 5,
132
+ "low_label": "Poor",
133
+ "high_label": "Excellent",
134
+ "required": True,
135
+ },
136
+ {
137
+ "title": "Which features do you use?",
138
+ "type": "checkboxes",
139
+ "options": ["Dashboard", "Reports", "API", "Integrations"],
140
+ },
141
+ {
142
+ "title": "Any other comments?",
143
+ "type": "paragraph",
144
+ },
145
+ ],
146
+ }
147
+ )
148
+
149
+ print(f"Form ID : {info.form_id}")
150
+ print(f"Share URL : {info.responder_uri}")
151
+ ```
152
+
153
+ ### 4. Read responses
154
+
155
+ ```python
156
+ responses = client.list_responses(info.form_id)
157
+ for r in responses:
158
+ print(r["responseId"], r.get("answers"))
159
+ ```
160
+
161
+ ## Supported question types
162
+
163
+ | `type` value | Google Forms equivalent |
164
+ |-------------------|------------------------------|
165
+ | `short_answer` | Short answer (single line) |
166
+ | `paragraph` | Paragraph (multi-line) |
167
+ | `multiple_choice` | Multiple choice (radio) |
168
+ | `checkboxes` | Checkboxes |
169
+ | `dropdown` | Dropdown |
170
+ | `scale` | Linear scale |
171
+ | `date` | Date |
172
+ | `time` | Time |
173
+ | `file_upload` | File upload |
174
+
175
+ ## Authentication setup
176
+
177
+ ### Service Account
178
+
179
+ 1. Create a Service Account in [Google Cloud Console](https://console.cloud.google.com/).
180
+ 2. Enable the **Google Forms API** and **Google Drive API**.
181
+ 3. Download the JSON key file.
182
+ 4. Share the target Google Drive folder with the service account email.
183
+
184
+ ### OAuth 2.0
185
+
186
+ 1. Create an OAuth 2.0 **Desktop app** client in Google Cloud Console.
187
+ 2. Download `client_secrets.json`.
188
+ 3. On first run, a browser window opens to authorise access.
189
+ 4. The token is cached in `token.json` for subsequent runs.
190
+
191
+ ## Development
192
+
193
+ ```bash
194
+ git clone https://github.com/andhit-r/gformlib.git
195
+ cd gformlib
196
+ pip install -e ".[dev]"
197
+ pytest
198
+ ```
199
+
200
+ ### Running the full test matrix with tox
201
+
202
+ ```bash
203
+ tox
204
+ ```
205
+
206
+ ## Contributing
207
+
208
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
209
+
210
+ ## License
211
+
212
+ [MIT](LICENSE)
@@ -0,0 +1,144 @@
1
+ # gformlib
2
+
3
+ [![PyPI version](https://badge.fury.io/py/gformlib.svg)](https://pypi.org/project/gformlib/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/gformlib.svg)](https://pypi.org/project/gformlib/)
5
+ [![CI](https://github.com/andhit-r/gformlib/actions/workflows/test.yml/badge.svg)](https://github.com/andhit-r/gformlib/actions/workflows/test.yml)
6
+ [![Documentation Status](https://readthedocs.org/projects/gformlib/badge/?version=latest)](https://gformlib.readthedocs.io/en/latest/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![codecov](https://codecov.io/gh/andhit-r/gformlib/branch/main/graph/badge.svg)](https://codecov.io/gh/andhit-r/gformlib)
9
+
10
+ **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](https://developers.google.com/forms/api/reference/rest).
11
+
12
+ ## Features
13
+
14
+ - Create Google Forms from a simple Python dict / JSON file
15
+ - All question types supported: short answer, paragraph, multiple choice, checkboxes, dropdown, scale, date, time, file upload
16
+ - Service-account and OAuth 2.0 authentication
17
+ - Full type annotations (PEP 561 compliant)
18
+ - Retrieve form responses with automatic pagination
19
+ - Professional project structure, ready to publish to PyPI
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install gformlib
25
+ ```
26
+
27
+ ## Quickstart
28
+
29
+ ### 1. Authenticate with a Service Account (recommended for servers)
30
+
31
+ ```python
32
+ from gformlib import GoogleFormsClient
33
+
34
+ client = GoogleFormsClient.from_service_account("path/to/service_account.json")
35
+ ```
36
+
37
+ ### 2. Authenticate with OAuth 2.0 (desktop / installed apps)
38
+
39
+ ```python
40
+ client = GoogleFormsClient.from_oauth_credentials(
41
+ "client_secrets.json",
42
+ token_file="token.json",
43
+ )
44
+ ```
45
+
46
+ ### 3. Create a form from a dict
47
+
48
+ ```python
49
+ info = client.create_form(
50
+ {
51
+ "title": "Customer Satisfaction Survey",
52
+ "description": "Tell us how we're doing.",
53
+ "questions": [
54
+ {
55
+ "title": "Your name",
56
+ "type": "short_answer",
57
+ "required": True,
58
+ },
59
+ {
60
+ "title": "Overall rating",
61
+ "type": "scale",
62
+ "low": 1,
63
+ "high": 5,
64
+ "low_label": "Poor",
65
+ "high_label": "Excellent",
66
+ "required": True,
67
+ },
68
+ {
69
+ "title": "Which features do you use?",
70
+ "type": "checkboxes",
71
+ "options": ["Dashboard", "Reports", "API", "Integrations"],
72
+ },
73
+ {
74
+ "title": "Any other comments?",
75
+ "type": "paragraph",
76
+ },
77
+ ],
78
+ }
79
+ )
80
+
81
+ print(f"Form ID : {info.form_id}")
82
+ print(f"Share URL : {info.responder_uri}")
83
+ ```
84
+
85
+ ### 4. Read responses
86
+
87
+ ```python
88
+ responses = client.list_responses(info.form_id)
89
+ for r in responses:
90
+ print(r["responseId"], r.get("answers"))
91
+ ```
92
+
93
+ ## Supported question types
94
+
95
+ | `type` value | Google Forms equivalent |
96
+ |-------------------|------------------------------|
97
+ | `short_answer` | Short answer (single line) |
98
+ | `paragraph` | Paragraph (multi-line) |
99
+ | `multiple_choice` | Multiple choice (radio) |
100
+ | `checkboxes` | Checkboxes |
101
+ | `dropdown` | Dropdown |
102
+ | `scale` | Linear scale |
103
+ | `date` | Date |
104
+ | `time` | Time |
105
+ | `file_upload` | File upload |
106
+
107
+ ## Authentication setup
108
+
109
+ ### Service Account
110
+
111
+ 1. Create a Service Account in [Google Cloud Console](https://console.cloud.google.com/).
112
+ 2. Enable the **Google Forms API** and **Google Drive API**.
113
+ 3. Download the JSON key file.
114
+ 4. Share the target Google Drive folder with the service account email.
115
+
116
+ ### OAuth 2.0
117
+
118
+ 1. Create an OAuth 2.0 **Desktop app** client in Google Cloud Console.
119
+ 2. Download `client_secrets.json`.
120
+ 3. On first run, a browser window opens to authorise access.
121
+ 4. The token is cached in `token.json` for subsequent runs.
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ git clone https://github.com/andhit-r/gformlib.git
127
+ cd gformlib
128
+ pip install -e ".[dev]"
129
+ pytest
130
+ ```
131
+
132
+ ### Running the full test matrix with tox
133
+
134
+ ```bash
135
+ tox
136
+ ```
137
+
138
+ ## Contributing
139
+
140
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
141
+
142
+ ## License
143
+
144
+ [MIT](LICENSE)
@@ -0,0 +1,102 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "gformlib"
7
+ version = "0.1.1"
8
+ description = "Create and manage Google Forms from JSON using the official Google Forms API."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ authors = [{ name = "Andhitia Rama", email = "andhitia.r@gmail.com" }]
12
+ keywords = ["google", "forms", "api", "survey", "automation"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Topic :: Internet :: WWW/HTTP",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ "Typing :: Typed",
25
+ ]
26
+ requires-python = ">=3.9"
27
+ dependencies = [
28
+ "google-api-python-client>=2.100.0",
29
+ "google-auth>=2.23.0",
30
+ "google-auth-oauthlib>=1.1.0",
31
+ "google-auth-httplib2>=0.2.0",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ dev = [
36
+ "pytest>=7.4",
37
+ "pytest-cov>=4.1",
38
+ "pytest-mock>=3.11",
39
+ "black>=23.0",
40
+ "isort>=5.12",
41
+ "mypy>=1.5",
42
+ "types-google-cloud-ndb",
43
+ "flake8>=6.1",
44
+ "tox>=4.11",
45
+ ]
46
+ docs = [
47
+ "sphinx>=7.1",
48
+ "sphinx-rtd-theme>=1.3",
49
+ "sphinxcontrib-httpdomain>=1.8",
50
+ "myst-parser>=2.0",
51
+ ]
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/andhit-r/gformlib"
55
+ Documentation = "https://gformlib.readthedocs.io"
56
+ Repository = "https://github.com/andhit-r/gformlib"
57
+ "Bug Tracker" = "https://github.com/andhit-r/gformlib/issues"
58
+ Changelog = "https://github.com/andhit-r/gformlib/blob/main/CHANGELOG.md"
59
+
60
+ [tool.setuptools.packages.find]
61
+ where = ["src"]
62
+
63
+ [tool.setuptools.package-data]
64
+ gformlib = ["py.typed"]
65
+
66
+ # ── Black ────────────────────────────────────────────────────────────────────
67
+ [tool.black]
68
+ line-length = 99
69
+ target-version = ["py39", "py310", "py311", "py312"]
70
+
71
+ # ── isort ────────────────────────────────────────────────────────────────────
72
+ [tool.isort]
73
+ profile = "black"
74
+ line_length = 99
75
+ src_paths = ["src", "tests"]
76
+
77
+ # ── pytest ───────────────────────────────────────────────────────────────────
78
+ [tool.pytest.ini_options]
79
+ testpaths = ["tests"]
80
+ addopts = "-v --tb=short"
81
+
82
+ # ── coverage ─────────────────────────────────────────────────────────────────
83
+ [tool.coverage.run]
84
+ source = ["src/gformlib"]
85
+ branch = true
86
+
87
+ [tool.coverage.report]
88
+ show_missing = true
89
+ skip_covered = false
90
+ fail_under = 80
91
+
92
+ # ── mypy ─────────────────────────────────────────────────────────────────────
93
+ [tool.mypy]
94
+ python_version = "3.10"
95
+ strict = true
96
+ ignore_missing_imports = true
97
+
98
+ [[tool.mypy.overrides]]
99
+ module = "gformlib.client"
100
+ # google-auth and google-api-python-client lack complete type stubs;
101
+ # all 4 mypy errors in this module originate from their untyped APIs.
102
+ ignore_errors = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,70 @@
1
+ """gformlib – Google Forms from JSON.
2
+
3
+ A Python library for creating and managing Google Forms programmatically,
4
+ wrapping the official `Google Forms API v1`_.
5
+
6
+ .. _Google Forms API v1: https://developers.google.com/forms/api/reference/rest
7
+
8
+ Quickstart::
9
+
10
+ from gformlib import GoogleFormsClient
11
+
12
+ client = GoogleFormsClient.from_service_account("service_account.json")
13
+ info = client.create_form(
14
+ {
15
+ "title": "My Survey",
16
+ "questions": [
17
+ {"title": "Your name", "type": "short_answer", "required": True},
18
+ {
19
+ "title": "Rating",
20
+ "type": "scale",
21
+ "low": 1,
22
+ "high": 5,
23
+ "low_label": "Poor",
24
+ "high_label": "Excellent",
25
+ },
26
+ ],
27
+ }
28
+ )
29
+ print(info.responder_uri)
30
+ """
31
+
32
+ from .builder import FormBuilder
33
+ from .client import DEFAULT_SCOPES, GoogleFormsClient
34
+ from .exceptions import (
35
+ APIError,
36
+ AuthenticationError,
37
+ FormCreationError,
38
+ FormUpdateError,
39
+ GFormLibError,
40
+ InvalidConfigError,
41
+ )
42
+ from .models import FormConfig, FormInfo, QuestionConfig, QuestionType
43
+ from .utils import parse_form_config, parse_question
44
+
45
+ __all__ = [
46
+ # Client
47
+ "GoogleFormsClient",
48
+ "DEFAULT_SCOPES",
49
+ # Builder
50
+ "FormBuilder",
51
+ # Models
52
+ "FormConfig",
53
+ "FormInfo",
54
+ "QuestionConfig",
55
+ "QuestionType",
56
+ # Utils
57
+ "parse_form_config",
58
+ "parse_question",
59
+ # Exceptions
60
+ "GFormLibError",
61
+ "AuthenticationError",
62
+ "FormCreationError",
63
+ "FormUpdateError",
64
+ "InvalidConfigError",
65
+ "APIError",
66
+ ]
67
+
68
+ __version__ = "0.1.0"
69
+ __author__ = "Andhitia Rama"
70
+ __email__ = "andhitia.r@gmail.com"