pyquickbase 0.1.0a1__py3-none-any.whl

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.
pyquickbase/errors.py ADDED
@@ -0,0 +1,110 @@
1
+ """Exceptions raised by pyquickbase. Everything here derives from `QuickbaseError`."""
2
+
3
+ from typing import Any
4
+
5
+
6
+ class QuickbaseError(Exception):
7
+ """Base class for every error raised by this library."""
8
+
9
+
10
+ class ConfigurationError(QuickbaseError, ValueError):
11
+ """The client was given invalid or missing settings."""
12
+
13
+
14
+ class NetworkError(QuickbaseError):
15
+ """The request failed before a response was received."""
16
+
17
+
18
+ class RequestTimeoutError(NetworkError):
19
+ """The request timed out. A timed-out write may still have been applied."""
20
+
21
+
22
+ class InvalidResponseError(QuickbaseError):
23
+ """Quickbase reported success, but the response body wasn't in the expected format."""
24
+
25
+
26
+ class ReadOnlyError(QuickbaseError):
27
+ """The client is read-only, and this request could change data. Nothing was sent."""
28
+
29
+
30
+ class QueryError(QuickbaseError, ValueError):
31
+ """A query can't be sent as written. Nothing was sent to Quickbase."""
32
+
33
+
34
+ class InvalidValueError(QuickbaseError, ValueError):
35
+ """A write can't be sent as written. Nothing was sent to Quickbase."""
36
+
37
+
38
+ class WriteError(QuickbaseError):
39
+ """Part of a write failed, and the rest may have been applied.
40
+
41
+ `result` is a `WriteResult` with the records that were written and the rows that failed, when
42
+ Quickbase reported them.
43
+ """
44
+
45
+ def __init__(self, summary: str, *, result: Any = None) -> None:
46
+ super().__init__(summary)
47
+ self.result = result
48
+
49
+
50
+ class UnknownTableError(QuickbaseError, LookupError):
51
+ """The app has no table with that name or ID."""
52
+
53
+
54
+ class UnknownFieldError(QuickbaseError, LookupError):
55
+ """The table has no field with that label or ID."""
56
+
57
+
58
+ class APIError(QuickbaseError):
59
+ """Quickbase answered with an unsuccessful status code.
60
+
61
+ `message` and `description` are Quickbase's own wording, when it sent any.
62
+ Include `request_id` when reporting a problem to Quickbase support.
63
+ """
64
+
65
+ def __init__(
66
+ self,
67
+ summary: str,
68
+ *,
69
+ status_code: int = 0,
70
+ method: str = "",
71
+ path: str = "",
72
+ message: str | None = None,
73
+ description: str | None = None,
74
+ request_id: str | None = None,
75
+ ) -> None:
76
+ super().__init__(summary)
77
+ self.status_code = status_code
78
+ self.method = method
79
+ self.path = path
80
+ self.message = message
81
+ self.description = description
82
+ self.request_id = request_id
83
+
84
+
85
+ class BadRequestError(APIError):
86
+ """400: Quickbase rejected the request as malformed."""
87
+
88
+
89
+ class AuthenticationError(APIError):
90
+ """401: the token is missing, invalid, or expired."""
91
+
92
+
93
+ class PermissionDeniedError(APIError):
94
+ """403: the token's user may not perform this action."""
95
+
96
+
97
+ class NotFoundError(APIError):
98
+ """404: the app, table, field, or record does not exist."""
99
+
100
+
101
+ class RateLimitError(APIError):
102
+ """429: retries ran out, or Quickbase asked for a longer wait than the retry policy allows."""
103
+
104
+ def __init__(self, summary: str, *, retry_after: float | None = None, **kwargs: object) -> None:
105
+ super().__init__(summary, **kwargs) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
106
+ self.retry_after = retry_after
107
+
108
+
109
+ class ServerError(APIError):
110
+ """5xx: Quickbase failed to process the request."""
pyquickbase/py.typed ADDED
File without changes
@@ -0,0 +1,223 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyquickbase
3
+ Version: 0.1.0a1
4
+ Summary: An unofficial, typed Python SDK for the Quickbase API, with sync and async clients.
5
+ Project-URL: Repository, https://github.com/matthew-williams-solutions/pyquickbase
6
+ Project-URL: Issues, https://github.com/matthew-williams-solutions/pyquickbase/issues
7
+ Project-URL: Changelog, https://github.com/matthew-williams-solutions/pyquickbase/blob/main/CHANGELOG.md
8
+ Author: Matthew Williams
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: api,async,client,quickbase,sdk
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Framework :: AnyIO
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: anyio<5,>=4.0
23
+ Requires-Dist: httpx<1,>=0.27
24
+ Description-Content-Type: text/markdown
25
+
26
+ # pyquickbase
27
+
28
+ An unofficial, typed Python SDK for the [Quickbase](https://www.quickbase.com/) API, with matching
29
+ sync and async clients.
30
+
31
+ > **Status: early alpha.** Anything may change before 1.0. This project is not affiliated with or endorsed by Quickbase, Inc.
32
+
33
+ ## What works today
34
+
35
+ - Sync and async clients with the same API, and support for asyncio and Trio
36
+ - Field labels instead of numeric IDs, and table names instead of table IDs
37
+ - A Python query builder that escapes values, and checks for hand-written queries that Quickbase would
38
+ otherwise accept and answer incorrectly
39
+ - Automatic paging, and records with real `date` and `datetime` values
40
+ - Automatic retries for rate limits, honoring `Retry-After`, and for connection failures
41
+ - Specific exceptions that include Quickbase's error message and request ID
42
+ - Tokens kept out of `repr`s, exceptions, and logs, and never sent to other hosts or over plain HTTP
43
+ - Creating, updating, and deleting records, with errors reported for each failed row
44
+ - Creating and changing tables, fields, and relationships
45
+ - `qb.request()` for calling any Quickbase endpoint directly
46
+
47
+ ## Coming next
48
+
49
+ Reports, formulas, file attachments, temporary tokens, and generated typed tables.
50
+
51
+ ## Usage
52
+
53
+ ```bash
54
+ pip install pyquickbase==0.1.0a1
55
+ ```
56
+
57
+ This is an alpha release, so pin the exact version.
58
+
59
+ ```python
60
+ from datetime import date
61
+ from pyquickbase import F, Quickbase
62
+
63
+ with Quickbase(realm="acme", token="your_user_token") as qb:
64
+ tasks = qb.app("bq1234567").table("Tasks")
65
+
66
+ overdue = (F("Status") != "Done") & (F("Due Date") < date.today())
67
+ for task in tasks.query(where=overdue, select=["Title", "Due Date"], order_by="-Due Date"):
68
+ print(task.id, task["Title"], task["Due Date"])
69
+
70
+ print(tasks.count(F("Status") == "Done"))
71
+ ```
72
+
73
+ The async client has the same API:
74
+
75
+ ```python
76
+ from pyquickbase import AsyncQuickbase, F
77
+
78
+ async with AsyncQuickbase(realm="acme", token="your_user_token") as qb:
79
+ tasks = qb.app("bq1234567").table("Tasks")
80
+ async for task in tasks.query(where=F("Status") == "Done"):
81
+ print(task["Title"])
82
+ ```
83
+
84
+ `Quickbase.from_env()` reads `QB_REALM` and `QB_USER_TOKEN` from the environment instead.
85
+
86
+ ## Writing queries
87
+
88
+ Build conditions with `F`, combining them with `&` and `|` and wrapping each in parentheses.
89
+
90
+ | Python | Matches |
91
+ |---|---|
92
+ | `F("Status") == "Done"`, `!=` | Equal, not equal, ignoring case |
93
+ | `F("Hours") > 10`, `>=`, `<`, `<=` | Numbers and dates |
94
+ | `F("Notes") == None` | Empty fields |
95
+ | `F("Title").contains("x")`, `.not_contains()` | Text anywhere in the value |
96
+ | `F("Title").starts_with("x")`, `.not_starts_with()` | Text at the start of the value |
97
+ | `F("Status").is_in(["Done", "Blocked"])` | Any of the values |
98
+ | `F("Tags").op("HAS", "x")` | Any other Quickbase operator |
99
+
100
+ Use `F` for any text you don't control. It escapes quotes and rejects values containing `{` or `}`,
101
+ which Quickbase can't search for and which could otherwise change the meaning of the query.
102
+
103
+ You can also pass a Quickbase query string as `where`, using field IDs:
104
+ `"({7.EX.'Done'}OR{7.EX.'Blocked'})AND{9.BF.'today'}"`. The SDK raises `QueryError` before sending a
105
+ string with a mistake that Quickbase would silently accept, such as a lowercase operator, which it
106
+ treats as "contains", or an unknown field, which matches nothing.
107
+
108
+ ## Reading records
109
+
110
+ `query()` fetches further pages as you iterate, and `limit` stops it early. Read values by label or
111
+ ID, with `record["Status"]` or `record[7]`. `dict(record)` gives you `{label: value}`. Record ID# is
112
+ always selected, and without `order_by`, records come back in Record ID# order so that pages stay
113
+ stable. For one page at a time, use `query_page()`, which returns the records, the `total` number of
114
+ matches, `has_more`, and `next_skip`.
115
+
116
+ Table and field metadata is cached for five minutes. Set `schema_ttl` on the client to change this,
117
+ or call `qb.clear_schema_cache()` after changing a table.
118
+
119
+ ## Writing records
120
+
121
+ Rows are dictionaries keyed by field label or ID. Python dates, timezone-aware datetimes, and
122
+ `Decimal` values are converted for you, and `None` clears a field.
123
+
124
+ | Method | What it does |
125
+ |---|---|
126
+ | `table.insert(rows)` | Creates records, and never changes existing ones |
127
+ | `table.update(rows)` | Changes records. Each row needs a `Record ID#`, and a missing record is an error |
128
+ | `table.upsert(rows, merge_on="Code")` | Updates the record whose unique field matches, or creates one |
129
+ | `table.delete(where)` | Deletes matching records and returns the count. `where` is required |
130
+
131
+ ```python
132
+ from pyquickbase import F, WriteError
133
+
134
+ result = tasks.insert([{"Title": "Pour slab", "Status": "Not Started", "Due Date": date.today()}])
135
+ print(result.created_ids)
136
+
137
+ tasks.update([{"Record ID#": 7, "Status": "Done", "Notes": None}])
138
+ tasks.delete(F("Status") == "Cancelled")
139
+
140
+ try:
141
+ tasks.insert(rows)
142
+ except WriteError as error:
143
+ print(error.result.created_ids) # these were written
144
+ for failed in error.result.errors:
145
+ print(rows[failed.index], failed.messages)
146
+ ```
147
+
148
+ Quickbase writes the rows it can and reports the rest, so a `WriteError` doesn't mean nothing changed.
149
+ Large writes are split into batches of 1,000 rows, which you can change with `batch_size`. Check
150
+ `error.result` before trying again.
151
+
152
+ ## Changing the schema
153
+
154
+ ```python
155
+ projects = app.create_table("Projects", single_record_name="Project")
156
+ projects.create_field("Name", "text")
157
+ projects.create_field("Status", "text-multiple-choice", choices=["Active", "Done"])
158
+ projects.create_field("Code", "text", unique=True)
159
+
160
+ tasks.create_relationship(projects, foreign_key_label="Project", lookup_fields=["Name"])
161
+ tasks.update_field("Notes", label="Comments")
162
+ tasks.delete_fields("Old Field")
163
+ tasks.drop(confirm="Tasks") # deletes the table and its records
164
+ ```
165
+
166
+ ## Handling errors
167
+
168
+ Every exception derives from `QuickbaseError`.
169
+
170
+ ```python
171
+ from pyquickbase import AuthenticationError, QuickbaseError, RateLimitError
172
+
173
+ try:
174
+ app = qb.request("GET", "/apps/bq1234567")
175
+ except AuthenticationError:
176
+ app = None
177
+ except RateLimitError as error:
178
+ print(f"Still rate limited. Try again in {error.retry_after} seconds.")
179
+ except QuickbaseError as error:
180
+ print(error)
181
+ ```
182
+
183
+ Quickbase answers with a 401, not a 404, for an app or table that doesn't exist, so
184
+ `AuthenticationError` can mean either a bad token or a wrong ID.
185
+
186
+ Only rate limits and connection failures are retried. A timed-out write isn't retried because
187
+ Quickbase may already have applied it, so check the data before trying again.
188
+
189
+ ## Limiting what a client can do
190
+
191
+ Pass `read_only=True` to guarantee a client can't change data. It only sends GET requests and record
192
+ queries, including through `qb.request()`, and raises `ReadOnlyError` for anything else without
193
+ contacting Quickbase.
194
+
195
+ To allow specific writes and nothing else, pass `allowed_writes={("POST", "/records")}` instead.
196
+
197
+ ## Customizing
198
+
199
+ Adjust retries with `RetryPolicy`. For proxies, custom TLS, logging hooks, or custom transports,
200
+ pass your own [httpx](https://www.python-httpx.org/) client, which you remain responsible for
201
+ closing.
202
+
203
+ ```python
204
+ import httpx
205
+ from pyquickbase import Quickbase, RetryPolicy
206
+
207
+ http_client = httpx.Client(proxy="http://proxy.internal:8080")
208
+ qb = Quickbase(
209
+ realm="acme",
210
+ token="your_user_token",
211
+ retry=RetryPolicy(max_retries=2),
212
+ user_agent="my-app/1.0",
213
+ http_client=http_client,
214
+ )
215
+ ```
216
+
217
+ ## Contributing
218
+
219
+ See [CONTRIBUTING.md](CONTRIBUTING.md). To report a vulnerability, see [SECURITY.md](SECURITY.md).
220
+
221
+ ## License
222
+
223
+ [MIT](LICENSE)
@@ -0,0 +1,24 @@
1
+ pyquickbase/__init__.py,sha256=LpL5txvyFaFSLPdcFrtdG0ZsA4hoGPnUVRGua0j-rBw,1707
2
+ pyquickbase/_auth.py,sha256=d6CnF9rOLn9-pyNxCh_1uEtJbuiWi4pVwM9esOZ_u5s,569
3
+ pyquickbase/_config.py,sha256=rONnqeKl1KitCGv_YbuMqEWx4v0X0IbrWIgBg57rEBk,3806
4
+ pyquickbase/_models.py,sha256=nXHg9M8gyUSv1hOTVrQbYu2ri44O2FlEKUhdP1wRCkE,8217
5
+ pyquickbase/_query.py,sha256=MlWjays75NqPk7g7uWvlbTeCV-fI0uml2K1ggjwnaDc,12174
6
+ pyquickbase/_response.py,sha256=XzeKe9jSJ7UrGog5OJoqmCu-kOzl9LVYxbGbkt_B4mE,3231
7
+ pyquickbase/_retry.py,sha256=oa2C0bEeikpa90KbsjdY_HPNbMayjL_IDygBQ8rVXzg,2568
8
+ pyquickbase/_schema.py,sha256=1MQ-xnAdWApaj0av65ix0RMaHiWVYgAI24rwr2QwBUY,1075
9
+ pyquickbase/_version.py,sha256=lmvUfjeqbjbsnD2PLlUjZbqEGZrq6yUD6t2LZsM61ak,24
10
+ pyquickbase/_writes.py,sha256=ozZQW-nkx1AVdBiYKlxGlktsfBJXgDie_umCP9Ab9lQ,4252
11
+ pyquickbase/errors.py,sha256=zHAwOZISJkMUlFBoBWtPOB48tDXlaav5dYG_ZhsCpHE,3281
12
+ pyquickbase/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ pyquickbase/_async/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ pyquickbase/_async/_client.py,sha256=UYgVE6uHkwlFJrdO15Bq6Xv8rDMHlw7JHDZ2CNwzGsg,5392
15
+ pyquickbase/_async/_resources.py,sha256=m2oUwT6leD9a28MQNaHdsGy9sAS42VjB14RUG9TYnOI,20641
16
+ pyquickbase/_async/_transport.py,sha256=nd1dB67a8arBPrlApvej9h6eSWdQ4YBytDl3DVsairk,2804
17
+ pyquickbase/_sync/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
+ pyquickbase/_sync/_client.py,sha256=gb0It1A6knvh-GRm7IYmr9uRUTjacwpOl_viRVLsPHE,5379
19
+ pyquickbase/_sync/_resources.py,sha256=1OuJphLr9b8chBgMgRTw1VLSVUMHuV2O_italqHro6w,20153
20
+ pyquickbase/_sync/_transport.py,sha256=10WQyfj_snPJv_hRuC8ovUH-EV0Ng9lSfiqDbaSHUK0,2829
21
+ pyquickbase-0.1.0a1.dist-info/METADATA,sha256=qp4GGEoMKHIvnKjfWcQW2AtKWw83XjwvDP45LOmjppQ,8615
22
+ pyquickbase-0.1.0a1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
23
+ pyquickbase-0.1.0a1.dist-info/licenses/LICENSE,sha256=UVm3Z-AksaPwv43NXxjs2hXTYDVOzFLwpl85CtIqZBM,1073
24
+ pyquickbase-0.1.0a1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Williams
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.