Writes¶
client.post(), put(), patch() and delete() return a WriteResult.
client.bulk() returns a BulkResult. See the writes guide.
WriteResult
dataclass
¶
What a write returned.
Attributes:
| Name | Type | Description |
|---|---|---|
dry_run |
bool
|
True if T3 only checked the request: format, required fields and types, not whether the records it names exist. Nothing reached Metrc. |
message |
str | None
|
The server's |
data |
Any
|
The parsed response body. |
response |
Response
|
The |
BulkResult
dataclass
¶
RowResult
dataclass
¶
RowResult(index: int, row: Mapping[str, Any], status: RowStatus = 'not_sent', message: str | None = None, data: Any = None, error: APIError | None = None)
One row of a bulk write.
status is valid (passed the dry run's static checks, not
submitted), invalid, submitted, failed or not_sent.
bulk
¶
bulk(client: T3Client, endpoint: str, rows: Iterable[Mapping[str, Any]], *, license: str | None = None, method: str | None = None, submit: bool | Literal['ask'] = False, confirm: bool = False, on_error: OnError = 'stop', log_to: str | Path | None = None, progress: bool | None = None, path_params: Mapping[str, Any] | None = None, dynamic: bool = False, batch_size: int = 1) -> BulkResult
Send many writes safely: validate every row, then submit.
For Metrc write routes:
- Every row is sent as a dry run and its result recorded. A dry run
checks format, required fields and types, not whether the records a
row names exist, so
validmeans "passed validation", not "Metrc will accept it". submit=Falsestops here.submit="ask"shows a summary (and any failures) and asks whether to submit, default no.submit=Truecarries on without asking unless some rows failed; then, in a terminal, it shows the failures and asks whether to submit only the valid rows.on_error="skip"submits them without asking.- Each valid row is sent with
submit=true, in order. Withon_error="stop", the first failed submit stops the rest.
Each row is one object. On routes whose body is a list (most Metrc writes), rows are wrapped in a list for you.
Routes with no dry run (immediate_write) can't be validated first, so
they need confirm=True ("I know this takes effect at once"), or
submit="ask" to ask a person before sending.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
T3Client
|
The client to send with. |
required |
endpoint
|
str
|
The write route's path (or endpoint ID). |
required |
rows
|
Iterable[Mapping[str, Any]]
|
One mapping per object to write. |
required |
license
|
str | None
|
Fills |
None
|
method
|
str | None
|
Picks the operation when a path has several write methods. |
None
|
submit
|
bool | Literal['ask']
|
|
False
|
confirm
|
bool
|
Required for routes with no dry run, unless |
False
|
on_error
|
OnError
|
|
'stop'
|
log_to
|
str | Path | None
|
Write the results to this CSV file. |
None
|
progress
|
bool | None
|
Show progress bars. Defaults to on when stderr is a terminal. |
None
|
path_params
|
Mapping[str, Any] | None
|
Values for the route's path parameters. |
None
|
dynamic
|
bool
|
Also ask T3 for the route's dynamic checks
( |
False
|
batch_size
|
int
|
Rows per request, on routes whose body is a list. A request that fails marks every row in it with the same error, so the default of 1 keeps each row's error separate. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
a bad |
NotInteractive
|
|
AuthError
|
the credential was rejected. It stops the run whatever
|