Skip to content

Commit c8c4dd3

Browse files
msfrisbieclaude
andcommitted
t3api-utils 2.0.0
Hard-break rewrite, as laid out in V2_DESIGN.md. - connect() with secret-key-first auth and keyring-backed profiles - Endpoint registry built from the T3 OpenAPI spec at runtime (cached live spec, bundled fallback), so new endpoints work without a release - httpx2 transport with retries that never resend a write on 5xx, a shared rate limiter and redacted HTTP logging - Parallel collect()/iter_rows(), dry-run-first writes and bulk(), server-side reports, tag lists, CSV/JSON export - `t3api` CLI (Typer) and an optional Textual inspector ([tui] extra) - DuckDB, pyarrow and the 1.x modules removed - 100% line and branch coverage, mypy strict, mkdocs site, CI on Linux/macOS/Windows and a PyPI trusted-publishing release workflow Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ff7a8ed commit c8c4dd3

158 files changed

Lines changed: 19958 additions & 16049 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: ci-${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test:
16+
name: Tests (${{ matrix.os }}, Python ${{ matrix.python-version }})
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, macos-latest, windows-latest]
22+
python-version: ["3.12", "3.13"]
23+
steps:
24+
- uses: actions/checkout@v7
25+
26+
- uses: astral-sh/setup-uv@v7
27+
with:
28+
enable-cache: true
29+
30+
- name: Install dependencies
31+
run: uv sync --python ${{ matrix.python-version }}
32+
33+
- name: Type check
34+
run: uv run mypy
35+
36+
# Coverage must be 100% (fail_under in pyproject.toml).
37+
# Sandbox smoke tests are skipped here: they need T3_SMOKE_SECRET_KEY.
38+
- name: Tests
39+
run: uv run pytest --cov --cov-branch --cov-report=term-missing
40+
41+
docs:
42+
name: Docs
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v7
46+
47+
- uses: astral-sh/setup-uv@v7
48+
with:
49+
enable-cache: true
50+
51+
- name: Install dependencies
52+
run: uv sync
53+
54+
- name: Build docs
55+
run: uv run mkdocs build --strict
56+
env:
57+
NO_MKDOCS_2_WARNING: "1"

‎.github/workflows/release.yml‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Publishes t3api-utils to PyPI when a GitHub release is published.
2+
#
3+
# BEFORE THIS CAN WORK, enable trusted publishing on PyPI:
4+
# https://pypi.org/manage/project/t3api-utils/settings/publishing/
5+
# Add a GitHub publisher with owner "classvsoftware", repository
6+
# "t3api-python-utils", workflow "release.yml" and environment "pypi".
7+
# Also create the "pypi" environment under the repository's Settings >
8+
# Environments (optionally with required reviewers). Until both exist, the
9+
# publish job fails at the upload step and nothing is released.
10+
#
11+
# Release checklist: bump the version in pyproject.toml, update CHANGELOG.md,
12+
# run scripts/update_spec.py and the sandbox smoke tests, then publish a
13+
# GitHub release whose tag matches the version (e.g. v2.0.0).
14+
15+
name: Release
16+
17+
on:
18+
release:
19+
types: [published]
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
build:
26+
name: Build distributions
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v7
30+
31+
- uses: astral-sh/setup-uv@v7
32+
33+
- name: Check the tag matches the package version
34+
run: |
35+
version=$(uv version --short)
36+
tag="${GITHUB_REF_NAME#v}"
37+
if [ "$version" != "$tag" ]; then
38+
echo "Release tag $GITHUB_REF_NAME doesn't match pyproject version $version" >&2
39+
exit 1
40+
fi
41+
42+
- name: Build
43+
run: uv build
44+
45+
- uses: actions/upload-artifact@v7
46+
with:
47+
name: dist
48+
path: dist/
49+
if-no-files-found: error
50+
51+
publish:
52+
name: Publish to PyPI
53+
needs: build
54+
runs-on: ubuntu-latest
55+
environment:
56+
name: pypi
57+
url: https://pypi.org/project/t3api-utils/
58+
permissions:
59+
id-token: write
60+
steps:
61+
- uses: actions/download-artifact@v8
62+
with:
63+
name: dist
64+
path: dist/
65+
66+
- uses: pypa/gh-action-pypi-publish@release/v1

‎CHANGELOG.md‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Changelog
2+
3+
## 2.0.0
4+
5+
A hard-break rewrite. No 1.x import path still works, and there is no
6+
compatibility layer. The [migration guide](https://classvsoftware.github.io/t3api-python-utils/migration/)
7+
maps every 1.x name to its replacement and shows the example scripts before
8+
and after.
9+
10+
### Highlights
11+
12+
- **`t3.connect()`** is the one way in. It finds a credential (argument, then
13+
`T3_SECRET_KEY` / `T3_JWT`, then the saved profile, then an interactive
14+
login only when a person can answer), validates it, and returns a
15+
`T3Client`. Scripts get from `import` to data in three lines.
16+
- **Secret keys first.** `t3api login` creates a T3 secret key from your Metrc
17+
login and saves it to a named profile, with the secret in the OS keyring.
18+
The Metrc password is never stored. `client.secret_keys` and `t3api keys`
19+
list, create, rotate and revoke keys. JWTs remain as a fallback.
20+
- **Spec-driven endpoints.** Endpoints are named by T3 endpoint ID
21+
(`METRC_ACTIVE_ITEMS`) or path, checked against the T3 OpenAPI spec at
22+
runtime. A live copy is fetched and cached per host, with the spec bundled
23+
in the package as a fallback, so new endpoints work without a release.
24+
Missing required parameters fail before any request is sent.
25+
- **Collections:** `client.collect()` loads every page of any of the 187
26+
paginated endpoints in parallel behind one shared rate limiter; 1.x's
27+
picker found 138. `client.iter_rows()` streams large collections. Rows are
28+
plain dicts, exactly as the API returns them.
29+
- **Safe writes.** Metrc writes are a dry run unless `submit=True`. Routes
30+
with no dry run reject `submit=`. `client.bulk()` validates every row before
31+
submitting any, and can log each row's outcome to CSV.
32+
- **Server-side reports:** `client.report()` downloads any of the 83 report
33+
endpoints as CSV, XLSX, JSON or a Google Sheet, for up to 20 licenses.
34+
`client.report_url()` builds a secret-key URL for spreadsheets to pull.
35+
- **Tag lists:** `client.tag_lists` creates lists from a CSV column or rows and
36+
resolves them to packages, items, harvests and more, with per-handle errors
37+
when something doesn't match.
38+
- **A `t3api` command** for login, profiles, keys, default license, endpoint
39+
search, `pull` (collection to CSV/JSON or the inspector), `report`,
40+
`tag-lists`, `inspect` and `spec info` / `spec refresh`.
41+
- **Local helpers:** `t3.filter_rows()` (indexed, with dotted paths),
42+
`t3.to_csv()` (UTF-8 with BOM for Excel, lists as JSON), `t3.to_json()`
43+
(optionally JSON Lines), `t3.read_rows()`, and `t3.pick_file()`.
44+
- **The Textual inspector** is kept as `t3.inspect()`, behind the optional
45+
`[tui]` extra.
46+
- **Errors keep their response.** Every `APIError` has `status_code`,
47+
`detail`, `errors`, `code` and the `response`; 1.x always reported
48+
`status_code=None`. Auth errors say whether to rotate a key or log in again.
49+
- Runs the same on Linux, macOS, Windows and in Jupyter. CI covers all three
50+
operating systems on Python 3.12 and 3.13, with 100% line and branch
51+
coverage.
52+
53+
### Fixed (compared with 1.x)
54+
55+
- Writes are no longer retried after a 5xx or a timeout, and a POST that gets
56+
a 400 is sent once, not three times. Reads retry only on connection errors,
57+
429, 502, 503 and 504, honouring `Retry-After`.
58+
- The rate limiter really limits: 1.x let 20 requests through in 0.2 seconds.
59+
- HTTP debug logging masks auth headers, secret keys in paths and queries, and
60+
password, OTP, OTP seed, secret key and token fields in bodies. 1.x logged
61+
credential-login bodies, password included.
62+
- Secret keys are sent in the `X-T3-API-Key` header instead of the URL.
63+
- Exported CSV lists are JSON text instead of Python reprs.
64+
65+
### Removed
66+
67+
- The async `T3APIClient`, its sync wrappers, `send_api_request`, the
68+
`request_*` helpers and the `get_collection` / `load_all_data_*` /
69+
`parallel_load_*` family. Use `T3Client` methods, or `client.http` for the
70+
configured `httpx2.Client`.
71+
- `get_authenticated_client_or_error()` and the other ~22 auth functions,
72+
including the `*_with_validation` variants.
73+
- API-key auth (`/v2/auth/apikey`, `API_KEY`, `API_STATE_CODE`).
74+
- The `.t3.env` file, `ConfigManager` and the 37 `EnvKeys`. 2.0 reads eight
75+
environment variables: `T3_SECRET_KEY`, `T3_JWT`, `T3_PROFILE`,
76+
`T3_LICENSE`, `T3_API_HOST`, `T3_SPEC`, `T3_LOG_HTTP`, `T3_LOG_FILE`.
77+
- DuckDB and pyarrow, and the `db/` module (relational tables, schema export).
78+
- `interactive_collection_handler` and the numbered menu, `match_collection_from_csv`,
79+
`save_collection_to_*` / `save_dicts_to_*`, `pick_collection`.
80+
- The `MetrcObject`, `MetrcCollectionResponse` and other TypedDicts.
81+
- The public `style/` module and `logging.setup_logging()`.
82+
- The `intro.py` tutorial, now the Getting started docs page.
83+
- Dependencies: `httpx` (replaced by `httpx2`), `duckdb`, `pyarrow`,
84+
`questionary`, `python-dotenv`, `certifi`.
85+
86+
### Packaging
87+
88+
- Still published as `t3api-utils`, imported as `t3api_utils`, for Python
89+
3.12 or later. License GPL-3.0-only. Built with `uv_build`.
90+
- Core dependencies: `httpx2`, `rich`, `typer`, `keyring`, `platformdirs`,
91+
`pyotp`, `tomli-w`. Textual is no longer installed by default; it's in the
92+
`[tui]` extra.
93+
94+
## 1.5.0
95+
96+
Final 1.x release. 1.x is frozen: no further releases or fixes. Pin
97+
`t3api-utils<2` to keep using it.

0 commit comments

Comments
 (0)