pyquickbase 0.1.0a1__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.
Files changed (46) hide show
  1. pyquickbase-0.1.0a1/.env.example +2 -0
  2. pyquickbase-0.1.0a1/.github/workflows/ci.yml +55 -0
  3. pyquickbase-0.1.0a1/.github/workflows/release.yml +32 -0
  4. pyquickbase-0.1.0a1/.gitignore +19 -0
  5. pyquickbase-0.1.0a1/.python-version +1 -0
  6. pyquickbase-0.1.0a1/CHANGELOG.md +28 -0
  7. pyquickbase-0.1.0a1/CONTRIBUTING.md +38 -0
  8. pyquickbase-0.1.0a1/LICENSE +21 -0
  9. pyquickbase-0.1.0a1/PKG-INFO +223 -0
  10. pyquickbase-0.1.0a1/README.md +198 -0
  11. pyquickbase-0.1.0a1/SECURITY.md +9 -0
  12. pyquickbase-0.1.0a1/docs/api-notes.md +97 -0
  13. pyquickbase-0.1.0a1/pyproject.toml +81 -0
  14. pyquickbase-0.1.0a1/scripts/generate_sync.py +105 -0
  15. pyquickbase-0.1.0a1/src/pyquickbase/__init__.py +73 -0
  16. pyquickbase-0.1.0a1/src/pyquickbase/_async/__init__.py +0 -0
  17. pyquickbase-0.1.0a1/src/pyquickbase/_async/_client.py +151 -0
  18. pyquickbase-0.1.0a1/src/pyquickbase/_async/_resources.py +511 -0
  19. pyquickbase-0.1.0a1/src/pyquickbase/_async/_transport.py +74 -0
  20. pyquickbase-0.1.0a1/src/pyquickbase/_auth.py +19 -0
  21. pyquickbase-0.1.0a1/src/pyquickbase/_config.py +93 -0
  22. pyquickbase-0.1.0a1/src/pyquickbase/_models.py +241 -0
  23. pyquickbase-0.1.0a1/src/pyquickbase/_query.py +315 -0
  24. pyquickbase-0.1.0a1/src/pyquickbase/_response.py +90 -0
  25. pyquickbase-0.1.0a1/src/pyquickbase/_retry.py +66 -0
  26. pyquickbase-0.1.0a1/src/pyquickbase/_schema.py +35 -0
  27. pyquickbase-0.1.0a1/src/pyquickbase/_sync/__init__.py +0 -0
  28. pyquickbase-0.1.0a1/src/pyquickbase/_sync/_client.py +152 -0
  29. pyquickbase-0.1.0a1/src/pyquickbase/_sync/_resources.py +506 -0
  30. pyquickbase-0.1.0a1/src/pyquickbase/_sync/_transport.py +75 -0
  31. pyquickbase-0.1.0a1/src/pyquickbase/_version.py +1 -0
  32. pyquickbase-0.1.0a1/src/pyquickbase/_writes.py +104 -0
  33. pyquickbase-0.1.0a1/src/pyquickbase/errors.py +110 -0
  34. pyquickbase-0.1.0a1/src/pyquickbase/py.typed +0 -0
  35. pyquickbase-0.1.0a1/tests/__init__.py +0 -0
  36. pyquickbase-0.1.0a1/tests/_async/test_client.py +369 -0
  37. pyquickbase-0.1.0a1/tests/_async/test_resources.py +305 -0
  38. pyquickbase-0.1.0a1/tests/_async/test_writes.py +391 -0
  39. pyquickbase-0.1.0a1/tests/_sync/test_client.py +368 -0
  40. pyquickbase-0.1.0a1/tests/_sync/test_resources.py +304 -0
  41. pyquickbase-0.1.0a1/tests/_sync/test_writes.py +390 -0
  42. pyquickbase-0.1.0a1/tests/conftest.py +6 -0
  43. pyquickbase-0.1.0a1/tests/test_core.py +146 -0
  44. pyquickbase-0.1.0a1/tests/test_query.py +396 -0
  45. pyquickbase-0.1.0a1/tests/test_writes.py +135 -0
  46. pyquickbase-0.1.0a1/uv.lock +463 -0
@@ -0,0 +1,2 @@
1
+ QB_REALM=yourrealm.quickbase.com
2
+ QB_USER_TOKEN=your_user_token
@@ -0,0 +1,55 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ quality:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
17
+ - run: uv sync --locked
18
+ - name: Lint
19
+ run: uv run ruff check .
20
+ - name: Check formatting
21
+ run: uv run ruff format --check .
22
+ - name: Check types
23
+ run: uv run pyright
24
+ - name: Check the generated sync code is current
25
+ run: uv run scripts/generate_sync.py --check
26
+ - name: Build the package
27
+ run: uv build
28
+
29
+ test:
30
+ runs-on: ubuntu-latest
31
+ strategy:
32
+ fail-fast: false
33
+ matrix:
34
+ python: ["3.11", "3.12", "3.13", "3.14"]
35
+ steps:
36
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
38
+ - run: uv run --locked --python ${{ matrix.python }} pytest --cov
39
+
40
+ test-lowest-dependencies:
41
+ runs-on: ubuntu-latest
42
+ steps:
43
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
44
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
45
+ - run: uv run --isolated --resolution lowest-direct --python 3.11 pytest
46
+
47
+ secrets:
48
+ runs-on: ubuntu-latest
49
+ steps:
50
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
51
+ with:
52
+ fetch-depth: 0
53
+ - uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
54
+ env:
55
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,32 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ publish:
12
+ runs-on: ubuntu-latest
13
+ environment: pypi
14
+ permissions:
15
+ contents: read
16
+ id-token: write # PyPI Trusted Publishing, so no API token is stored anywhere
17
+ steps:
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
20
+ - run: uv sync --locked
21
+ - name: Check the tag matches the package version
22
+ run: |
23
+ version=$(uv run python -c "import pyquickbase; print(pyquickbase.__version__)")
24
+ test "$GITHUB_REF_NAME" = "v$version"
25
+ - name: Run the checks
26
+ run: |
27
+ uv run ruff check .
28
+ uv run pyright
29
+ uv run scripts/generate_sync.py --check
30
+ uv run pytest
31
+ - run: uv build
32
+ - run: uv publish --trusted-publishing always
@@ -0,0 +1,19 @@
1
+ # Secrets: never commit real credentials
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+
6
+ # Python
7
+ __pycache__/
8
+ *.py[cod]
9
+ .venv/
10
+ build/
11
+ dist/
12
+ *.egg-info/
13
+
14
+ # Tool caches
15
+ .coverage
16
+ .coverage.*
17
+ htmlcov/
18
+ .pytest_cache/
19
+ .ruff_cache/
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0a1] - 2026-11-02
10
+
11
+ First alpha release.
12
+
13
+ ### Added
14
+
15
+ - `Quickbase` and `AsyncQuickbase` clients with `request()` for calling any endpoint.
16
+ - `RetryPolicy`, with retries for HTTP 429 and connection failures.
17
+ - The `QuickbaseError` exception hierarchy.
18
+ - `qb.app()` and `app.table()`, with app, table, field, and relationship metadata and a schema cache.
19
+ - `F` for building queries by field label, with values escaped for you.
20
+ - Checks that reject broken `where` strings that Quickbase would otherwise accept.
21
+ - `table.query()` for automatic paging, plus `query_page()` and `count()`.
22
+ - `Record`, with access by label or ID and date and timestamp conversion.
23
+ - `read_only=True` on the clients, which refuses any request that could change data.
24
+ - `allowed_writes` on the clients, which limits them to reads plus the writes you list.
25
+ - `parse_where()` for inspecting a hand-written `where` string.
26
+ - `table.insert()`, `update()`, `upsert()`, and `delete()`, with per-row error reporting in `WriteError`.
27
+ - `app.create_table()`, `table.create_field()`, `update_field()`, `delete_fields()`,
28
+ `create_relationship()`, and `drop()`.
@@ -0,0 +1,38 @@
1
+ # Contributing
2
+
3
+ ## Setup
4
+
5
+ Install [uv](https://docs.astral.sh/uv/), then run `uv sync`. Before opening a pull request, run:
6
+
7
+ ```bash
8
+ uv run ruff check .
9
+ uv run ruff format .
10
+ uv run pyright
11
+ uv run scripts/generate_sync.py
12
+ uv run pytest --cov
13
+ ```
14
+
15
+ Tests use mocked HTTP and need no Quickbase account.
16
+
17
+ ## Sync and async code
18
+
19
+ **Only edit the async code.** `src/pyquickbase/_sync/` and `tests/_sync/` are generated from their
20
+ `_async` counterparts, and CI fails if they are out of date. After changing async code, run
21
+ `uv run scripts/generate_sync.py` and commit the result.
22
+
23
+ Code that does no network access, such as parsing and validation, belongs outside `_async` so both
24
+ clients share it.
25
+
26
+ ## Public API
27
+
28
+ Anything exported from `pyquickbase/__init__.py` or defined in `errors.py` is public. Modules
29
+ starting with `_` are private and may change at any time. Update `CHANGELOG.md` for changes that
30
+ users would notice.
31
+
32
+ ## Secrets
33
+
34
+ Never commit real tokens, realm names, or customer data, including in test fixtures. Tokens must
35
+ never appear in exceptions, `repr`s, or logs.
36
+
37
+ `docs/api-notes.md` tracks which Quickbase API behavior has been confirmed. Please update it if you
38
+ confirm or disprove something.
@@ -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.
@@ -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,198 @@
1
+ # pyquickbase
2
+
3
+ An unofficial, typed Python SDK for the [Quickbase](https://www.quickbase.com/) API, with matching
4
+ sync and async clients.
5
+
6
+ > **Status: early alpha.** Anything may change before 1.0. This project is not affiliated with or endorsed by Quickbase, Inc.
7
+
8
+ ## What works today
9
+
10
+ - Sync and async clients with the same API, and support for asyncio and Trio
11
+ - Field labels instead of numeric IDs, and table names instead of table IDs
12
+ - A Python query builder that escapes values, and checks for hand-written queries that Quickbase would
13
+ otherwise accept and answer incorrectly
14
+ - Automatic paging, and records with real `date` and `datetime` values
15
+ - Automatic retries for rate limits, honoring `Retry-After`, and for connection failures
16
+ - Specific exceptions that include Quickbase's error message and request ID
17
+ - Tokens kept out of `repr`s, exceptions, and logs, and never sent to other hosts or over plain HTTP
18
+ - Creating, updating, and deleting records, with errors reported for each failed row
19
+ - Creating and changing tables, fields, and relationships
20
+ - `qb.request()` for calling any Quickbase endpoint directly
21
+
22
+ ## Coming next
23
+
24
+ Reports, formulas, file attachments, temporary tokens, and generated typed tables.
25
+
26
+ ## Usage
27
+
28
+ ```bash
29
+ pip install pyquickbase==0.1.0a1
30
+ ```
31
+
32
+ This is an alpha release, so pin the exact version.
33
+
34
+ ```python
35
+ from datetime import date
36
+ from pyquickbase import F, Quickbase
37
+
38
+ with Quickbase(realm="acme", token="your_user_token") as qb:
39
+ tasks = qb.app("bq1234567").table("Tasks")
40
+
41
+ overdue = (F("Status") != "Done") & (F("Due Date") < date.today())
42
+ for task in tasks.query(where=overdue, select=["Title", "Due Date"], order_by="-Due Date"):
43
+ print(task.id, task["Title"], task["Due Date"])
44
+
45
+ print(tasks.count(F("Status") == "Done"))
46
+ ```
47
+
48
+ The async client has the same API:
49
+
50
+ ```python
51
+ from pyquickbase import AsyncQuickbase, F
52
+
53
+ async with AsyncQuickbase(realm="acme", token="your_user_token") as qb:
54
+ tasks = qb.app("bq1234567").table("Tasks")
55
+ async for task in tasks.query(where=F("Status") == "Done"):
56
+ print(task["Title"])
57
+ ```
58
+
59
+ `Quickbase.from_env()` reads `QB_REALM` and `QB_USER_TOKEN` from the environment instead.
60
+
61
+ ## Writing queries
62
+
63
+ Build conditions with `F`, combining them with `&` and `|` and wrapping each in parentheses.
64
+
65
+ | Python | Matches |
66
+ |---|---|
67
+ | `F("Status") == "Done"`, `!=` | Equal, not equal, ignoring case |
68
+ | `F("Hours") > 10`, `>=`, `<`, `<=` | Numbers and dates |
69
+ | `F("Notes") == None` | Empty fields |
70
+ | `F("Title").contains("x")`, `.not_contains()` | Text anywhere in the value |
71
+ | `F("Title").starts_with("x")`, `.not_starts_with()` | Text at the start of the value |
72
+ | `F("Status").is_in(["Done", "Blocked"])` | Any of the values |
73
+ | `F("Tags").op("HAS", "x")` | Any other Quickbase operator |
74
+
75
+ Use `F` for any text you don't control. It escapes quotes and rejects values containing `{` or `}`,
76
+ which Quickbase can't search for and which could otherwise change the meaning of the query.
77
+
78
+ You can also pass a Quickbase query string as `where`, using field IDs:
79
+ `"({7.EX.'Done'}OR{7.EX.'Blocked'})AND{9.BF.'today'}"`. The SDK raises `QueryError` before sending a
80
+ string with a mistake that Quickbase would silently accept, such as a lowercase operator, which it
81
+ treats as "contains", or an unknown field, which matches nothing.
82
+
83
+ ## Reading records
84
+
85
+ `query()` fetches further pages as you iterate, and `limit` stops it early. Read values by label or
86
+ ID, with `record["Status"]` or `record[7]`. `dict(record)` gives you `{label: value}`. Record ID# is
87
+ always selected, and without `order_by`, records come back in Record ID# order so that pages stay
88
+ stable. For one page at a time, use `query_page()`, which returns the records, the `total` number of
89
+ matches, `has_more`, and `next_skip`.
90
+
91
+ Table and field metadata is cached for five minutes. Set `schema_ttl` on the client to change this,
92
+ or call `qb.clear_schema_cache()` after changing a table.
93
+
94
+ ## Writing records
95
+
96
+ Rows are dictionaries keyed by field label or ID. Python dates, timezone-aware datetimes, and
97
+ `Decimal` values are converted for you, and `None` clears a field.
98
+
99
+ | Method | What it does |
100
+ |---|---|
101
+ | `table.insert(rows)` | Creates records, and never changes existing ones |
102
+ | `table.update(rows)` | Changes records. Each row needs a `Record ID#`, and a missing record is an error |
103
+ | `table.upsert(rows, merge_on="Code")` | Updates the record whose unique field matches, or creates one |
104
+ | `table.delete(where)` | Deletes matching records and returns the count. `where` is required |
105
+
106
+ ```python
107
+ from pyquickbase import F, WriteError
108
+
109
+ result = tasks.insert([{"Title": "Pour slab", "Status": "Not Started", "Due Date": date.today()}])
110
+ print(result.created_ids)
111
+
112
+ tasks.update([{"Record ID#": 7, "Status": "Done", "Notes": None}])
113
+ tasks.delete(F("Status") == "Cancelled")
114
+
115
+ try:
116
+ tasks.insert(rows)
117
+ except WriteError as error:
118
+ print(error.result.created_ids) # these were written
119
+ for failed in error.result.errors:
120
+ print(rows[failed.index], failed.messages)
121
+ ```
122
+
123
+ Quickbase writes the rows it can and reports the rest, so a `WriteError` doesn't mean nothing changed.
124
+ Large writes are split into batches of 1,000 rows, which you can change with `batch_size`. Check
125
+ `error.result` before trying again.
126
+
127
+ ## Changing the schema
128
+
129
+ ```python
130
+ projects = app.create_table("Projects", single_record_name="Project")
131
+ projects.create_field("Name", "text")
132
+ projects.create_field("Status", "text-multiple-choice", choices=["Active", "Done"])
133
+ projects.create_field("Code", "text", unique=True)
134
+
135
+ tasks.create_relationship(projects, foreign_key_label="Project", lookup_fields=["Name"])
136
+ tasks.update_field("Notes", label="Comments")
137
+ tasks.delete_fields("Old Field")
138
+ tasks.drop(confirm="Tasks") # deletes the table and its records
139
+ ```
140
+
141
+ ## Handling errors
142
+
143
+ Every exception derives from `QuickbaseError`.
144
+
145
+ ```python
146
+ from pyquickbase import AuthenticationError, QuickbaseError, RateLimitError
147
+
148
+ try:
149
+ app = qb.request("GET", "/apps/bq1234567")
150
+ except AuthenticationError:
151
+ app = None
152
+ except RateLimitError as error:
153
+ print(f"Still rate limited. Try again in {error.retry_after} seconds.")
154
+ except QuickbaseError as error:
155
+ print(error)
156
+ ```
157
+
158
+ Quickbase answers with a 401, not a 404, for an app or table that doesn't exist, so
159
+ `AuthenticationError` can mean either a bad token or a wrong ID.
160
+
161
+ Only rate limits and connection failures are retried. A timed-out write isn't retried because
162
+ Quickbase may already have applied it, so check the data before trying again.
163
+
164
+ ## Limiting what a client can do
165
+
166
+ Pass `read_only=True` to guarantee a client can't change data. It only sends GET requests and record
167
+ queries, including through `qb.request()`, and raises `ReadOnlyError` for anything else without
168
+ contacting Quickbase.
169
+
170
+ To allow specific writes and nothing else, pass `allowed_writes={("POST", "/records")}` instead.
171
+
172
+ ## Customizing
173
+
174
+ Adjust retries with `RetryPolicy`. For proxies, custom TLS, logging hooks, or custom transports,
175
+ pass your own [httpx](https://www.python-httpx.org/) client, which you remain responsible for
176
+ closing.
177
+
178
+ ```python
179
+ import httpx
180
+ from pyquickbase import Quickbase, RetryPolicy
181
+
182
+ http_client = httpx.Client(proxy="http://proxy.internal:8080")
183
+ qb = Quickbase(
184
+ realm="acme",
185
+ token="your_user_token",
186
+ retry=RetryPolicy(max_retries=2),
187
+ user_agent="my-app/1.0",
188
+ http_client=http_client,
189
+ )
190
+ ```
191
+
192
+ ## Contributing
193
+
194
+ See [CONTRIBUTING.md](CONTRIBUTING.md). To report a vulnerability, see [SECURITY.md](SECURITY.md).
195
+
196
+ ## License
197
+
198
+ [MIT](LICENSE)
@@ -0,0 +1,9 @@
1
+ # Security policy
2
+
3
+ Please don't report vulnerabilities in public issues. Use GitHub's
4
+ [private vulnerability reporting](https://github.com/matthew-williams-solutions/pyquickbase/security/advisories/new)
5
+ instead, and include steps to reproduce the problem.
6
+
7
+ Only the latest release is supported. This is a volunteer project, so response times may vary.
8
+
9
+ If a Quickbase token may have been exposed, revoke it in Quickbase right away.