You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 73b8069
Browse filesBrowse the repository at this point in the historyBrowse files
Fixes and additions from porting the T3 example scripts to 2.0:
- bulk() wraps rows in a list on routes whose body is an array (68 of
85 Metrc writes), which previously answered every row with a 500
- bulk(submit="ask") validates, shows a summary and asks before
submitting; bulk(batch_size=N); dynamic=True on writes and bulk()
- warn when a json= body's shape doesn't match the spec
- public t3.confirm(), t3.ask(parse=...) and t3.choose()
- sandbox: ignore production default licenses, warn about licenses the
session doesn't have, T3_SANDBOX, t3api --sandbox, client.sandbox and
client.hostname
- client.download() for file endpoints, streamed and renamed atomically
- include= on collect(), iter_rows() and get(), sent repeated
- to_csv()/to_json() accept a folder
- docs: dry runs are static validation only; array bodies, uploads,
downloads, super collections, prompts guide
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-**Endpoint kinds** come from spec structure alone (`registry.classify`): collection, report, metrc_write, immediate_write, file, object, other. Tests check named endpoints' kinds, not counts.
113
-
-**Writes**: `metrc_write` routes are a dry run unless `submit=True`; `immediate_write` routes reject `submit=` entirely. `bulk()` validates every row before submitting; row statuses are valid/invalid/submitted/failed/not_sent.
115
+
-**Writes**: `metrc_write` routes are a dry run unless `submit=True`; `immediate_write` routes reject `submit=` entirely. A dry run is static validation only (format, required fields, types), never call it more than that. `bulk()` validates every row before submitting; row statuses are valid/invalid/submitted/failed/not_sent. `submit="ask"` raises `NotInteractive` without a terminal before sending anything.
116
+
-**Body shape**: `Endpoint.body_type` comes from the spec. Most Metrc write routes take a JSON list; `bulk()` wraps each row in a list for them, and single writes warn when the `json=` shape doesn't match.
114
117
-**Retries** (`_http.RetryTransport`): GET/HEAD/OPTIONS retry on connection errors and 429/502/503/504; writes retry only on 429 and pre-send connection failures. Never retry a write on 5xx or a post-send timeout. Max 3 attempts.
115
118
-**Credentials**: secret keys go in the `X-T3-API-Key` header, never the query string, except `report_url()`. The Metrc password is never stored.
116
119
-**Redaction**: HTTP debug logs mask auth headers, `/v2/auth/secretkey/{key}` paths, `secretKey=` queries, and `password`/`otp`/`otpSeed`/`secretKey`/`accessToken`/`refreshToken` body fields.
117
120
-**Default license** (`client.license`) is applied only to endpoints whose `licenseNumber` is required. An explicit `license=` always wins.
121
+
-**Sandbox**: `connect(sandbox=True)` / `T3_SANDBOX` ignores `T3_LICENSE` and the profile's license, `enter_sandbox()` clears `client.license`, and explicit licenses are checked against the session's (the sandbox returns an empty 200 for other licenses). The CLI's `--sandbox` applies to data commands only, never to `login`, `logout`, `keys` or `license`.
Copy file name to clipboardExpand all lines: docs/guide/authentication.md
+33-6Lines changed: 33 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,12 +104,15 @@ then `https://api.trackandtrace.tools`.
104
104
available as `client.license`, and it's used only by calls whose endpoint
105
105
requires a `licenseNumber`. A license passed to a call always wins.
106
106
107
+
In the [sandbox](#sandbox), only `connect(license=...)` counts: `T3_LICENSE`
108
+
and the profile's license are production licenses.
109
+
107
110
### Other connect() options
108
111
109
112
| Option | Default | What it does |
110
113
|---|---|---|
111
114
|`validate`|`True`| Check the credential with `/v2/auth/whoami`. |
112
-
|`sandbox`|`False`| Swap the credential for a Metrc sandbox JWT. See [Sandbox](#sandbox). |
115
+
|`sandbox`|`T3_SANDBOX`, then `False`| Swap the credential for a Metrc sandbox JWT. See [Sandbox](#sandbox). |
113
116
|`spec`|`T3_SPEC`, then `"auto"`|`"bundled"` pins the spec shipped with the package. See [Endpoints and the spec](endpoints-and-spec.md#where-the-spec-comes-from). |
114
117
|`rate_limit`|`10.0`| Requests per second across all threads. `None` turns it off. |
115
118
|`concurrency`|`10`| Threads used to fetch collection pages. |
@@ -164,15 +167,16 @@ The first profile you create becomes the default.
164
167
165
168
## Environment variables
166
169
167
-
These are the only environment variables 2.0 reads. There's no`.t3.env`
168
-
file.
170
+
These are the only environment variables the library reads. There's no
171
+
`.t3.env`file.
169
172
170
173
| Variable | What it does |
171
174
|---|---|
172
175
|`T3_SECRET_KEY`| Secret key to use. Wins over any saved profile. |
173
176
|`T3_JWT`| JWT to use, if `T3_SECRET_KEY` isn't set. |
174
177
|`T3_PROFILE`| Profile to use instead of the default. `t3api` commands that take `--profile` read it too. |
175
-
|`T3_LICENSE`| Default license number. |
178
+
|`T3_LICENSE`| Default license number. Ignored in the sandbox. |
179
+
|`T3_SANDBOX`|`1`, `true`, `yes` or `on` makes `connect()` and the `t3api` data commands use the [Metrc sandbox](#sandbox). |
176
180
|`T3_API_HOST`| T3 API base URL, e.g. a staging host. |
177
181
|`T3_SPEC`|`bundled` pins the spec shipped with the package. |
178
182
|`T3_LOG_HTTP`|`1`, `true`, `yes` or `on` logs every request and response at DEBUG. |
@@ -254,13 +258,36 @@ production:
254
258
255
259
```python
256
260
with t3.connect(sandbox=True) as client:
257
-
lic = client.licenses()[0]["licenseNumber"]
261
+
lic = client.pick_license() # the sandbox's own licenses
Copy file name to clipboardExpand all lines: docs/guide/endpoints-and-spec.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,9 +66,12 @@ Each `Endpoint` has:
66
66
|`tags`|`("Items",)`|
67
67
|`summary`|`"List of active items"`|
68
68
|`params`| the operation's parameters, each with `name`, `location`, `required`, `description` and `schema`|
69
+
|`body_type`|`"array"` or `"object"` for routes with a JSON body, else `None`. `body_is_array` is `True` for the [list routes](writes.md#array-bodies). |
69
70
70
71
`ep.param("licenseNumber")` returns one parameter, and `ep.label()` gives a
71
-
readable `GET /v2/items (METRC_ACTIVE_ITEMS)`.
72
+
readable `GET /v2/items (METRC_ACTIVE_ITEMS)`. A parameter's `choices` are the
73
+
values the spec allows, such as a super collection's `include` values, or `()`
74
+
when it doesn't list any.
72
75
73
76
In a terminal, `client.pick_endpoint()` shows a numbered table of collections
74
77
that you can narrow by typing. `client.pick_endpoint(kind=None)` shows every
@@ -92,7 +95,7 @@ structure. The rules are checked top to bottom:
92
95
|`report`| Can respond with CSV or XLSX | 83 |`report()`, `report_url()`|
93
96
|`metrc_write`| Non-GET that takes the `submit` parameter | 85 |`post()` / `put()` / `patch()` / `delete()`, `bulk()`|
94
97
|`immediate_write`| Non-GET without `submit`| 28 | the same, without `submit=`|
95
-
|`file`| GET returning a PDF or an image | 5 |`get()`, which returns `bytes`|
98
+
|`file`| GET returning a PDF or an image | 5 |`download()` to a file, or `get()`, which returns `bytes`|
96
99
|`object`| GET with an `{object_id}` path parameter | 144 |`get(..., object_id=...)`|
97
100
|`other`| Everything else, e.g. `/v2/licenses`, `/v2/auth/whoami`| 124 |`get()` / `request()`|
98
101
@@ -125,6 +128,7 @@ The common collection parameters have Python names:
125
128
|`filter_logic`|`filterLogic`|
126
129
|`sort`|`sort`|
127
130
|`mask` (string or list) |`collectionMask`, comma-joined |
131
+
|`include` (string or list) | one `include=` per item |
128
132
|`page_size`|`pageSize`|
129
133
130
134
`page`, `submit` and `secretKey` are managed by the library; don't pass them in
0 commit comments