Python scripts that use the T3 API to read and change data in Metrc. Each one is a single file built on t3api-utils, and each runs with uv, which installs Python and everything else the script needs.
-
Clone this repository, or download any one script. Every script stands alone.
-
Run the intro:
uv run getting-started/intro.py
The first run asks for your Metrc login and offers to create a T3 secret key. The key is kept in your operating system's keyring, so later runs don't ask again. To set up a login without running a script, use uvx --from t3api-utils t3api login.
-
It runs with no arguments and asks for anything it needs, such as a license or an input file.
-
It also takes flags for the same things, so it can run unattended.
--helpshows each script's flags and its input format.Flag Meaning -l,--licenseLicense number -p,--profileSaved t3apiprofile--sandboxUse the Metrc sandbox -i,--inputInput file -o,--outputOutput file or folder (default output/)-y,--yesSubmit without asking, once validation passes -
Scripts that change Metrc data never do it by surprise. Each one:
- checks every input row against your current data
- sends each row as a dry run, which T3 validates without passing anything to Metrc
- shows you a summary
- asks before submitting, with "No" as the default answer
-
Each write run logs every row's outcome to a results file in
output/. -
Output files go to
output/, named with the license and time so that runs never overwrite each other.
The Metrc sandbox is a separate copy of Metrc with test data. Add --sandbox to any script, or set T3_SANDBOX=1, to run it there:
uv run basics/use-the-sandbox.py
uv run packages/move-packages-from-csv.py --sandbox
- Licenses differ. The sandbox has its own, such as
SF-SBX-1-101, and the script asks you to pick one. - Your Metrc account needs sandbox access.
Run every write script in the sandbox before you use it on a real license.
Changes says what a script can change, always after asking: data in Metrc, or only your T3 account. A dash means it's read-only.
| Script | What it does | Changes |
|---|---|---|
getting-started/intro.py |
Log in, list your licenses, and export one license's active packages | — |
Reading data
| Script | What it does | Changes |
|---|---|---|
basics/connect-and-whoami.py |
Show which credential, profile and Metrc host you're connected with | — |
basics/list-licenses.py |
List every license your login can see, and save the list to CSV | — |
basics/export-a-collection.py |
Load every row of any collection and save it to CSV | — |
basics/filter-sort-mask.py |
Load only the rows and fields you need, sorted, by letting the server filter | — |
basics/super-collections.py |
Load packages with their lab results and source harvests attached | — |
basics/stream-a-large-collection.py |
Export a collection too big for memory, writing each row as it arrives | — |
basics/get-one-object.py |
Fetch one package by its ID | — |
basics/multiple-licenses.py |
Load several licenses at once and count rows per license | — |
basics/browse-in-the-inspector.py |
Browse a collection row by row in the terminal inspector | — |
basics/find-endpoints.py |
Search the API's endpoints by keyword, pick a collection, and export it | — |
basics/search.py |
Search packages, plants, transfers, items and more for a label, name or number | — |
basics/check-permissions.py |
List what your Metrc login may do on a license, page by page | — |
basics/match-rows-from-csv.py |
Keep only the rows that match a CSV file | — |
basics/tag-lists.py |
Turn a column of tag labels into full package records with a T3 tag list | T3 |
basics/run-a-report.py |
Download a server-built XLSX or CSV report for one or more licenses | — |
Writing data, errors and automation
| Script | What it does | Changes |
|---|---|---|
basics/dry-run-and-submit.py |
One write the safe way: dry run, confirm, submit. It creates one strain | Metrc |
basics/bulk-writes.py |
Validate a file of request bodies against any write route with bulk() |
Metrc |
basics/handle-errors.py |
Make six common mistakes on purpose and show the error each raises | — |
basics/use-the-sandbox.py |
Connect to the Metrc sandbox, look around, and optionally move sandbox plants | Sandbox only |
basics/scheduled-job.py |
Run unattended: a template for cron jobs and GitHub Actions | — |
basics/raw-http-escape-hatch.py |
Call the API through client.http, for routes the spec doesn't list |
— |
| Script | What it does | Changes |
|---|---|---|
packages/move-packages-from-csv.py |
Move packages to new locations | Metrc |
packages/adjust-packages-from-csv.py |
Adjust package quantities up or down, with a reason | Metrc |
packages/finish-packages-from-csv.py |
Finish empty packages | Metrc |
packages/add-package-notes-from-csv.py |
Add a note to each package | Metrc |
packages/split-package.py |
Split part of one package into a new package with its own tag | Metrc |
packages/export-lab-results.py |
Export every active package's lab results, one row per test | — |
packages/export-package-history.py |
Export package history, one row per event | — |
| Script | What it does | Changes |
|---|---|---|
items/create-item.py |
Create one item (a product type, such as "Blue Dream Flower") | Metrc |
items/create-strains-from-csv.py |
Create strains | Metrc |
items/discontinue-items-from-csv.py |
Discontinue the items named in a CSV file | Metrc |
items/upload-item-photo.py |
Upload a photo for an item. It takes effect at once, so the script asks first | Metrc |
items/download-item-photos.py |
Download the product, label and packaging photos of your items | — |
| Script | What it does | Changes |
|---|---|---|
transfers/download-manifest-pdfs.py |
Download manifest PDFs: one you pick, the ones you name, or all of them | — |
transfers/download-transfer-coa-pdfs.py |
Download every COA PDF for the packages on one transfer | — |
transfers/export-outgoing-transfers.py |
Export outgoing transfers created in a date range | — |
transfers/void-transfers-from-csv.py |
Void outgoing transfers, by manifest number | Metrc |
| Script | What it does | Changes |
|---|---|---|
sales/export-sales.py |
Export open and finalized sales receipts in a date range | — |
sales/void-sales-receipts-from-csv.py |
Void sales receipts, unfinalizing finalized ones first | Metrc |
| Script | What it does | Changes |
|---|---|---|
cultivation/move-plants-from-csv.py |
Move plants to new locations | Metrc |
cultivation/change-growth-phase-from-csv.py |
Change plants' growth phase, such as vegetative to flowering | Metrc |
cultivation/record-plant-waste-from-csv.py |
Record plant waste | Metrc |
cultivation/finish-harvests-from-csv.py |
Finish harvests | Metrc |
cultivation/create-packages-from-harvest.py |
Create one package from a harvest | Metrc |
Every -from-csv script comes with a .sample.csv next to it that shows the columns it expects.
Set T3_SECRET_KEY instead of a saved login, and pass every flag the script would otherwise ask for. Write scripts also need --yes, because without a terminal they refuse to submit rather than wait for an answer. basics/scheduled-job.py shows the setup for cron and GitHub Actions.
STYLE_GUIDE.md explains how these scripts are organized and why, and includes copy-ready templates. Before opening a pull request, run the offline checks:
uv run tools/check-scripts.py