libtea 0.1.1__tar.gz → 0.3.0__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 (67) hide show
  1. {libtea-0.1.1 → libtea-0.3.0}/.github/workflows/ci.yaml +3 -2
  2. {libtea-0.1.1 → libtea-0.3.0}/.github/workflows/pypi.yaml +5 -0
  3. {libtea-0.1.1 → libtea-0.3.0}/.gitignore +1 -0
  4. libtea-0.3.0/.pre-commit-config.yaml +15 -0
  5. libtea-0.3.0/CLAUDE.md +93 -0
  6. libtea-0.3.0/PKG-INFO +531 -0
  7. libtea-0.3.0/README.md +499 -0
  8. libtea-0.3.0/docs/FUTURE.md +23 -0
  9. libtea-0.3.0/docs/cli.md +370 -0
  10. libtea-0.3.0/docs/plans/2025-02-25-tea-client-design.md +218 -0
  11. libtea-0.3.0/docs/plans/2026-02-25-v0.2.0-design.md +745 -0
  12. libtea-0.3.0/docs/plans/2026-02-26-v0.3.0-design.md +710 -0
  13. {libtea-0.1.1 → libtea-0.3.0}/pyproject.toml +31 -5
  14. {libtea-0.1.1 → libtea-0.3.0/src}/libtea/__init__.py +49 -1
  15. libtea-0.3.0/src/libtea/_cli_entry.py +17 -0
  16. libtea-0.3.0/src/libtea/_cli_fmt.py +546 -0
  17. libtea-0.3.0/src/libtea/_constants.py +14 -0
  18. libtea-0.3.0/src/libtea/_hashing.py +65 -0
  19. libtea-0.3.0/src/libtea/_http.py +423 -0
  20. libtea-0.3.0/src/libtea/_security.py +106 -0
  21. libtea-0.3.0/src/libtea/_validation.py +82 -0
  22. libtea-0.3.0/src/libtea/cli.py +721 -0
  23. libtea-0.3.0/src/libtea/client.py +723 -0
  24. libtea-0.3.0/src/libtea/discovery.py +380 -0
  25. libtea-0.3.0/src/libtea/exceptions.py +97 -0
  26. libtea-0.3.0/src/libtea/models.py +552 -0
  27. libtea-0.3.0/src/libtea/protocols.py +145 -0
  28. libtea-0.3.0/tests/cli/__init__.py +0 -0
  29. libtea-0.3.0/tests/cli/test_cli.py +1413 -0
  30. libtea-0.3.0/tests/cli/test_cli_fmt.py +953 -0
  31. libtea-0.3.0/tests/client/__init__.py +0 -0
  32. libtea-0.3.0/tests/client/test_cache.py +204 -0
  33. libtea-0.3.0/tests/client/test_client.py +823 -0
  34. libtea-0.3.0/tests/client/test_discovery.py +750 -0
  35. {libtea-0.1.1/tests → libtea-0.3.0/tests/client}/test_download.py +14 -0
  36. {libtea-0.1.1/tests → libtea-0.3.0/tests/client}/test_http.py +250 -86
  37. libtea-0.3.0/tests/client/test_iterators.py +319 -0
  38. libtea-0.3.0/tests/conftest.py +45 -0
  39. libtea-0.3.0/tests/integration/__init__.py +0 -0
  40. libtea-0.3.0/tests/unit/__init__.py +0 -0
  41. libtea-0.3.0/tests/unit/test_cli_entry.py +21 -0
  42. libtea-0.3.0/tests/unit/test_hashing.py +60 -0
  43. {libtea-0.1.1/tests → libtea-0.3.0/tests/unit}/test_models.py +337 -23
  44. libtea-0.3.0/tests/unit/test_protocols.py +14 -0
  45. libtea-0.3.0/tests/unit/test_security.py +224 -0
  46. libtea-0.3.0/tests/unit/test_validation.py +122 -0
  47. {libtea-0.1.1 → libtea-0.3.0}/uv.lock +240 -24
  48. libtea-0.1.1/.pre-commit-config.yaml +0 -7
  49. libtea-0.1.1/CLAUDE.md +0 -30
  50. libtea-0.1.1/PKG-INFO +0 -269
  51. libtea-0.1.1/README.md +0 -241
  52. libtea-0.1.1/libtea/_http.py +0 -257
  53. libtea-0.1.1/libtea/client.py +0 -393
  54. libtea-0.1.1/libtea/discovery.py +0 -224
  55. libtea-0.1.1/libtea/exceptions.py +0 -58
  56. libtea-0.1.1/libtea/models.py +0 -330
  57. libtea-0.1.1/tests/conftest.py +0 -25
  58. libtea-0.1.1/tests/test_client.py +0 -469
  59. libtea-0.1.1/tests/test_discovery.py +0 -346
  60. {libtea-0.1.1 → libtea-0.3.0}/.github/dependabot.yml +0 -0
  61. {libtea-0.1.1 → libtea-0.3.0}/.github/workflows/codeql.yaml +0 -0
  62. {libtea-0.1.1 → libtea-0.3.0}/LICENSE +0 -0
  63. {libtea-0.1.1 → libtea-0.3.0/src}/libtea/py.typed +0 -0
  64. {libtea-0.1.1 → libtea-0.3.0}/tests/__init__.py +0 -0
  65. {libtea-0.1.1/tests → libtea-0.3.0/tests/integration}/test_integration.py +0 -0
  66. {libtea-0.1.1/tests → libtea-0.3.0/tests/unit}/test_exceptions.py +0 -0
  67. {libtea-0.1.1/tests → libtea-0.3.0/tests/unit}/test_version.py +0 -0
@@ -15,7 +15,8 @@ jobs:
15
15
  - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16
16
  - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
17
17
  - run: uv python install ${{ matrix.python-version }}
18
- - run: uv sync
18
+ - run: uv sync --extra cli
19
19
  - run: uv run ruff check .
20
20
  - run: uv run ruff format --check .
21
- - run: uv run pytest --cov=libtea --cov-report=term-missing
21
+ - run: uv run pytest --cov-fail-under=90
22
+ - run: uv build
@@ -53,6 +53,11 @@ jobs:
53
53
 
54
54
  - uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
55
55
 
56
+ - name: Run tests
57
+ run: |
58
+ uv sync --extra cli
59
+ uv run pytest --cov-fail-under=90
60
+
56
61
  - name: Build package
57
62
  run: uv build
58
63
 
@@ -46,6 +46,7 @@ htmlcov/
46
46
  nosetests.xml
47
47
  coverage.xml
48
48
  *.cover
49
+ *,cover
49
50
  *.py.cover
50
51
  .hypothesis/
51
52
  .pytest_cache/
@@ -0,0 +1,15 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.15.0
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
8
+ - repo: local
9
+ hooks:
10
+ - id: mypy
11
+ name: mypy
12
+ entry: uv run mypy
13
+ language: system
14
+ types: [python]
15
+ pass_filenames: false
libtea-0.3.0/CLAUDE.md ADDED
@@ -0,0 +1,93 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ **py-libtea** is a hand-crafted Python client library for the Transparency Exchange API (TEA) v0.3.0-beta.2. Consumer-focused (read-only); publisher API is not yet supported (blocked on TEA spec). Licensed Apache 2.0, maintained under sbomify.
8
+
9
+ ## Build & Dev Commands
10
+
11
+ ```bash
12
+ uv sync # Install all dependencies
13
+ uv run pytest # Run full test suite with coverage
14
+ uv run pytest tests/client/test_client.py -v # Run a single test file
15
+ uv run pytest tests/unit/test_security.py::TestSsrfProtection::test_rejects_cgnat_ip -v # Single test
16
+ uv run mypy # Type check (strict mode)
17
+ uv run ruff check . # Lint
18
+ uv run ruff format --check . # Format check
19
+ uv run ruff format . # Auto-format
20
+ uv build # Build wheel and sdist
21
+ ```
22
+
23
+ ## Code Conventions
24
+
25
+ - **Layout**: src/ layout (`src/libtea/`), hatchling build backend
26
+ - **Python**: >=3.11 (enables `StrEnum`, `X | Y` union syntax)
27
+ - **Line length**: 120, ruff rules: E, F, I
28
+ - **Models**: Pydantic v2 with `frozen=True`, `extra="ignore"`, `alias_generator=to_camel`
29
+ - **HTTP mocking**: `responses` library (not `unittest.mock` for HTTP)
30
+ - **Coverage**: Branch coverage enabled, target ~97%
31
+
32
+ ## Architecture
33
+
34
+ The library has a layered design with strict separation of concerns:
35
+
36
+ ```
37
+ __init__.py Public API re-exports (all models, exceptions, client, discovery)
38
+ client.py TeaClient — high-level consumer API, checksum verification
39
+ ↓ uses
40
+ _validation.py Input validation helpers (path segments, page size/offset, Pydantic wrappers)
41
+ _http.py TeaHttpClient — low-level requests wrapper, auth, streaming downloads
42
+ Also: probe_endpoint() for endpoint failover
43
+ _security.py SSRF protection (_validate_download_url, DNS rebinding checks, internal IP detection)
44
+ _hashing.py Checksum hash builders (SHA-*, BLAKE2b-*, MD5)
45
+ discovery.py TEI parsing, .well-known/tea fetching, SemVer endpoint selection, redirect SSRF protection
46
+ models.py Pydantic v2 models for all TEA domain objects (frozen, camelCase aliases)
47
+ exceptions.py Exception hierarchy (all inherit from TeaError)
48
+ cli.py click CLI (optional dependency, thin wrapper over TeaClient)
49
+ _cli_fmt.py Rich output formatters for all CLI commands (tables, panels, escape helpers)
50
+ _cli_entry.py Entry point wrapper that handles missing CLI extras gracefully
51
+ ```
52
+
53
+ **Key design patterns:**
54
+
55
+ - `TeaClient` delegates all HTTP to `TeaHttpClient` — never calls `requests` directly
56
+ - Bearer tokens are NOT sent to artifact download URLs (separate unauthenticated session prevents token leakage to CDNs)
57
+ - Downloads follow redirects manually with SSRF validation at each hop
58
+ - Discovery redirects are validated against internal networks (SSRF protection via `_security._validate_download_url`)
59
+ - `_validation._validate()` wraps Pydantic `ValidationError` into `TeaValidationError` so all client errors are `TeaError` subclasses
60
+ - Endpoint failover: `from_well_known()` probes candidates in priority order, skipping unreachable ones
61
+ - `probe_endpoint()` lives in `_http.py` (not `client.py`) to maintain the HTTP layer boundary
62
+ - `_raise_for_status()` uses bounded reads (201 bytes) for error body snippets to avoid memory issues on streaming responses
63
+ - CLI formatters in `_cli_fmt.py` escape all server-controlled strings with `rich.markup.escape()` to prevent Rich markup injection
64
+
65
+ **Auth**: Bearer token and basic auth are supported. Token and basic_auth are mutually exclusive. HTTP (non-TLS) with credentials is rejected.
66
+
67
+ ## Critical Implementation Rules
68
+
69
+ - **NEVER** use `from __future__ import annotations` in files containing Pydantic models — it breaks Pydantic v2 runtime type evaluation
70
+ - `pydantic >= 2.1.0` is the floor (for `pydantic.alias_generators.to_camel`)
71
+ - `requests` auto-encodes query params — do NOT pre-encode with `urllib.parse.quote()`
72
+ - When mocking with `responses` library, use `requests.ConnectionError` as the body exception (not Python's built-in `ConnectionError` — they are different classes)
73
+ - `ChecksumAlgorithm` values may arrive as `SHA_256` (underscore) or `SHA-256` (hyphen) from servers — the `@field_validator` in `Checksum` normalizes both
74
+ - BLAKE3 is in the enum for spec completeness but NOT supported at runtime (not in stdlib `hashlib`) — raises `TeaChecksumError`
75
+ - `Identifier.id_type` is typed as `str` (not `IdentifierType` enum) so unknown types from future spec versions pass through
76
+ - CGNAT range (100.64.0.0/10, RFC 6598) is checked separately in SSRF protection because `ipaddress.is_private` misses it on Python 3.11+
77
+
78
+ ## TEA Spec Reference
79
+
80
+ The TEA spec repo should be cloned to `/tmp/transparency-exchange-api/` for cross-referencing:
81
+
82
+ ```bash
83
+ git clone https://github.com/CycloneDX/transparency-exchange-api /tmp/transparency-exchange-api
84
+ ```
85
+
86
+ Key spec files: `spec/openapi.yaml`, `discovery/readme.md`, `auth/readme.md`
87
+
88
+ ## Design Docs
89
+
90
+ - `docs/plans/2025-02-25-tea-client-design.md` — v0.1.0 original design
91
+ - `docs/plans/2026-02-25-v0.2.0-design.md` — v0.2.0 (CLE, SemVer, failover, CLI)
92
+ - `docs/plans/2026-02-26-v0.3.0-design.md` — v0.3.0 (httpx migration, async client)
93
+ - `docs/FUTURE.md` — Items blocked on external factors (Publisher API)
libtea-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,531 @@
1
+ Metadata-Version: 2.4
2
+ Name: libtea
3
+ Version: 0.3.0
4
+ Summary: Python client library for the Transparency Exchange API (TEA)
5
+ Project-URL: Homepage, https://github.com/sbomify/py-libtea
6
+ Project-URL: Repository, https://github.com/sbomify/py-libtea
7
+ Project-URL: Documentation, https://github.com/sbomify/py-libtea#readme
8
+ Project-URL: Bug Tracker, https://github.com/sbomify/py-libtea/issues
9
+ Project-URL: Changelog, https://github.com/sbomify/py-libtea/releases
10
+ Author-email: sbomify <hello@sbomify.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: cyclonedx,sbom,security,supply-chain,tea,transparency-exchange-api,vex
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: pydantic<3,>=2.1.0
26
+ Requires-Dist: requests<3,>=2.32.4
27
+ Requires-Dist: semver<4,>=3.0.4
28
+ Provides-Extra: cli
29
+ Requires-Dist: click<9,>=8.0; extra == 'cli'
30
+ Requires-Dist: rich>=13.0.0; extra == 'cli'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # libtea
34
+
35
+ [![CI](https://github.com/sbomify/py-libtea/actions/workflows/ci.yaml/badge.svg)](https://github.com/sbomify/py-libtea/actions/workflows/ci.yaml)
36
+ [![PyPI version](https://img.shields.io/pypi/v/libtea.svg)](https://pypi.org/project/libtea/)
37
+ [![Python](https://img.shields.io/pypi/pyversions/libtea.svg)](https://pypi.org/project/libtea/)
38
+ [![License](https://img.shields.io/github/license/sbomify/py-libtea.svg)](https://github.com/sbomify/py-libtea/blob/master/LICENSE)
39
+
40
+ Python client library for the [Transparency Exchange API (TEA)](https://transparency.exchange/) v0.3.0-beta.2.
41
+
42
+ TEA is an open standard for discovering and retrieving software transparency artifacts (SBOMs, VEX, build metadata) for any software product or component. A [TEI identifier](https://github.com/CycloneDX/transparency-exchange-api/blob/main/discovery/readme.md) resolves via DNS to the right endpoint, similar to how email uses MX records — so consumers can fetch artifacts without knowing which server hosts them.
43
+
44
+ **Specification:** [Ecma TC54-TG1](https://tc54.org/tea/) | [OpenAPI spec](https://github.com/CycloneDX/transparency-exchange-api)
45
+
46
+ > **Status**: Alpha — API is subject to change.
47
+
48
+ ### Features
49
+
50
+ - Auto-discovery via `.well-known/tea` and TEI URNs
51
+ - Flexible version negotiation — connects to older server versions within the same major series
52
+ - Products, components, releases, and versioned collections
53
+ - Search by PURL, CPE, or TEI identifier
54
+ - Pagination auto-iterators for search results
55
+ - Bulk parallel fetch for products, releases, and artifacts
56
+ - Common Lifecycle Enumeration (CLE) — ECMA-428 lifecycle events
57
+ - Artifact download with on-the-fly checksum verification (MD5 through BLAKE2b)
58
+ - Optional TTL response caching
59
+ - Endpoint failover with SemVer-compatible version selection
60
+ - SSRF protection — blocks private IPs, cloud metadata endpoints, DNS rebinding
61
+ - Bearer token and HTTP basic auth authentication
62
+ - Bearer token isolation — tokens are never sent to artifact download hosts
63
+ - `TeaClientProtocol` for dependency inversion and test doubles
64
+ - Typed Pydantic v2 models with full camelCase/snake_case conversion
65
+ - Structured exception hierarchy with error context
66
+ - CLI with rich-formatted output, JSON mode, and verbose logging
67
+
68
+ ## Installation
69
+
70
+ ```bash
71
+ pip install libtea
72
+ ```
73
+
74
+ To include the CLI (`tea-cli`):
75
+
76
+ ```bash
77
+ pip install libtea[cli]
78
+ ```
79
+
80
+ ## Quick start
81
+
82
+ ```python
83
+ from libtea import TeaClient
84
+
85
+ # Auto-discover the sbomify TEA server from its .well-known/tea
86
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
87
+ # Discover a product by TEI
88
+ results = client.discover(
89
+ "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
90
+ )
91
+ for info in results:
92
+ print(info.product_release_uuid, info.servers)
93
+
94
+ # Get a product release
95
+ pr = client.get_product_release(results[0].product_release_uuid)
96
+ print(pr.version, pr.product_name)
97
+ ```
98
+
99
+ Or connect directly to a known endpoint:
100
+
101
+ ```python
102
+ client = TeaClient(
103
+ base_url="https://trust.sbomify.com/tea/v0.3.0-beta.2",
104
+ timeout=30.0,
105
+ )
106
+ ```
107
+
108
+ Using `from_well_known`, you can also override the spec version and timeout:
109
+
110
+ ```python
111
+ client = TeaClient.from_well_known(
112
+ "trust.sbomify.com",
113
+ timeout=15.0,
114
+ version="0.3.0-beta.2", # default
115
+ )
116
+ ```
117
+
118
+ ## Usage
119
+
120
+ ### Discovery
121
+
122
+ ```python
123
+ from libtea import TeaClient
124
+
125
+ # Discover sbomify products via TEI
126
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
127
+ results = client.discover(
128
+ "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
129
+ )
130
+ for info in results:
131
+ print(info.product_release_uuid, info.servers)
132
+ ```
133
+
134
+ Low-level discovery functions are also available:
135
+
136
+ ```python
137
+ from libtea.discovery import parse_tei, fetch_well_known, select_endpoint
138
+
139
+ # Parse a TEI URN
140
+ tei_type, domain, identifier = parse_tei(
141
+ "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
142
+ )
143
+
144
+ # Fetch and select an endpoint manually
145
+ well_known = fetch_well_known("trust.sbomify.com")
146
+ endpoint = select_endpoint(well_known, "0.3.0-beta.2")
147
+ print(endpoint.url, endpoint.priority)
148
+ ```
149
+
150
+ Supported TEI types: `uuid`, `purl`, `hash`, `swid`, `eanupc`, `gtin`, `asin`, `udi`.
151
+
152
+ ### Search
153
+
154
+ ```python
155
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
156
+ # Search by PURL
157
+ results = client.search_products("PURL", "pkg:github/sbomify/sbomify")
158
+ for product in results.results:
159
+ print(product.name, product.uuid)
160
+
161
+ # Search product releases (with pagination)
162
+ releases = client.search_product_releases(
163
+ "PURL", "pkg:github/sbomify/sbomify",
164
+ page_offset=0, page_size=100,
165
+ )
166
+ print(releases.total_results)
167
+ ```
168
+
169
+ ### Auto-paginated iterators
170
+
171
+ For iterating over large result sets without manual page management:
172
+
173
+ ```python
174
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
175
+ # Iterate all matching products (handles pagination automatically)
176
+ for product in client.iter_products("PURL", "pkg:github/sbomify/sbomify"):
177
+ print(product.name)
178
+
179
+ # Iterate all product releases by identifier
180
+ for release in client.iter_product_releases("PURL", "pkg:github/sbomify/sbomify"):
181
+ print(release.version)
182
+
183
+ # Iterate all releases for a specific product UUID
184
+ for release in client.iter_releases_for_product("product-uuid"):
185
+ print(release.version, release.created_date)
186
+ ```
187
+
188
+ ### Bulk parallel fetch
189
+
190
+ Fetch multiple resources by UUID in parallel:
191
+
192
+ ```python
193
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
194
+ products = client.get_products(["uuid-1", "uuid-2", "uuid-3"])
195
+ releases = client.get_product_releases_bulk(["uuid-1", "uuid-2"])
196
+ artifacts = client.get_artifacts(["uuid-1", "uuid-2"])
197
+ ```
198
+
199
+ Results are returned in the same order as the input UUIDs. Use `max_workers=1` for serial execution.
200
+
201
+ ### Products and releases
202
+
203
+ ```python
204
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
205
+ product = client.get_product("product-uuid")
206
+ print(product.name, product.identifiers)
207
+
208
+ releases = client.get_product_releases("product-uuid", page_size=25)
209
+ for release in releases.results:
210
+ print(release.version, release.created_date)
211
+
212
+ # Single product release
213
+ pr = client.get_product_release("release-uuid")
214
+ print(pr.version, pr.components)
215
+
216
+ # Product release collections
217
+ latest = client.get_product_release_collection_latest("release-uuid")
218
+ all_versions = client.get_product_release_collections("release-uuid")
219
+ specific = client.get_product_release_collection("release-uuid", 3)
220
+ ```
221
+
222
+ ### Components
223
+
224
+ ```python
225
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
226
+ component = client.get_component("component-uuid")
227
+ releases = client.get_component_releases("component-uuid")
228
+
229
+ # Get a component release with its latest collection
230
+ cr = client.get_component_release("release-uuid")
231
+ print(cr.release.version, len(cr.latest_collection.artifacts))
232
+ ```
233
+
234
+ ### Collections and artifacts
235
+
236
+ ```python
237
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
238
+ collection = client.get_component_release_collection_latest("release-uuid")
239
+ for artifact in collection.artifacts:
240
+ print(artifact.name, artifact.type)
241
+
242
+ # All collection versions for a component release
243
+ all_versions = client.get_component_release_collections("release-uuid")
244
+
245
+ # Specific collection version
246
+ collection_v3 = client.get_component_release_collection("release-uuid", 3)
247
+ ```
248
+
249
+ ### Downloading artifacts with checksum verification
250
+
251
+ ```python
252
+ from pathlib import Path
253
+
254
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
255
+ artifact = client.get_artifact("artifact-uuid")
256
+ fmt = artifact.formats[0]
257
+
258
+ # Downloads and verifies checksums on-the-fly; returns the dest path
259
+ path = client.download_artifact(
260
+ fmt.url,
261
+ Path("sbom.json"),
262
+ verify_checksums=fmt.checksums,
263
+ )
264
+ ```
265
+
266
+ Supported checksum algorithms: MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA3-256, SHA3-384, SHA3-512, BLAKE2b-256, BLAKE2b-384, BLAKE2b-512. BLAKE3 is recognized in the model but not verifiable (Python's `hashlib` has no BLAKE3 support — a clear error is raised).
267
+
268
+ Artifact downloads use a separate unauthenticated HTTP session so the bearer token is never leaked to third-party hosts (CDNs, Maven Central, etc.). On checksum mismatch, the downloaded file is automatically deleted.
269
+
270
+ ### Common Lifecycle Enumeration (CLE)
271
+
272
+ ```python
273
+ with TeaClient.from_well_known("trust.sbomify.com") as client:
274
+ # Get lifecycle events for a product release
275
+ cle = client.get_product_release_cle("release-uuid")
276
+ for event in cle.events:
277
+ print(event.type, event.effective)
278
+
279
+ # CLE is available for all entity types
280
+ client.get_product_cle("product-uuid")
281
+ client.get_component_cle("component-uuid")
282
+ client.get_component_release_cle("release-uuid")
283
+ ```
284
+
285
+ ### Authentication
286
+
287
+ ```python
288
+ from libtea import TeaClient
289
+
290
+ # Bearer token
291
+ client = TeaClient.from_well_known("trust.sbomify.com", token="your-token")
292
+
293
+ # HTTP basic auth
294
+ client = TeaClient.from_well_known("trust.sbomify.com", basic_auth=("user", "password"))
295
+ ```
296
+
297
+ ### Response caching
298
+
299
+ Enable optional TTL-based caching to avoid repeated API calls:
300
+
301
+ ```python
302
+ # Cache GET responses for 5 minutes
303
+ client = TeaClient("https://trust.sbomify.com/tea/v0.3.0-beta.2", cache_ttl=300)
304
+ product = client.get_product("uuid") # HTTP call
305
+ product = client.get_product("uuid") # served from cache
306
+
307
+ client.clear_cache() # manually invalidate
308
+ ```
309
+
310
+ Only JSON API responses are cached — artifact downloads are never cached.
311
+
312
+ ### Private network access
313
+
314
+ By default, artifact downloads are blocked from private/internal IPs (SSRF protection). For local development:
315
+
316
+ ```python
317
+ client = TeaClient.from_well_known(
318
+ "trust.local",
319
+ scheme="http",
320
+ allow_private_ips=True, # allows downloads from 127.0.0.1, 10.x, etc.
321
+ )
322
+ ```
323
+
324
+ Scheme validation and cloud metadata endpoint blocking are always enforced.
325
+
326
+ ### Testing with TeaClientProtocol
327
+
328
+ Use the `TeaClientProtocol` for dependency inversion in consumer code:
329
+
330
+ ```python
331
+ from libtea import TeaClientProtocol
332
+
333
+ def fetch_sbom(client: TeaClientProtocol, product_uuid: str):
334
+ """Accepts any object matching the TeaClient interface."""
335
+ product = client.get_product(product_uuid)
336
+ return product.name
337
+ ```
338
+
339
+ This allows using mock objects in tests without depending on the concrete `TeaClient` class.
340
+
341
+ ## CLI
342
+
343
+ The `tea-cli` command provides a terminal interface for all TEA operations. Install with `pip install libtea[cli]`. See the [full CLI reference](docs/cli.md) for detailed documentation.
344
+
345
+ ### Global options
346
+
347
+ These flags can be placed before or after the subcommand name. They appear under each subcommand's `--help` output.
348
+
349
+ ```
350
+ --json Output raw JSON instead of rich-formatted tables
351
+ --verbose, -v Show verbose output (libtea debug logs)
352
+ --debug, -d Show debug output (full HTTP firehose including urllib3)
353
+ --allow-private-ips Allow artifact downloads from private/internal IPs
354
+ --version Show version
355
+ ```
356
+
357
+ All commands also accept connection options: `--base-url`, `--domain`, `--token`, `--auth`, `--use-http`, `--port`.
358
+
359
+ ### Discover
360
+
361
+ ```bash
362
+ # Discover sbomify product releases via TEI
363
+ tea-cli discover "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
364
+
365
+ # UUIDs only (for scripting)
366
+ tea-cli discover -q "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
367
+
368
+ # JSON output
369
+ tea-cli --json discover "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
370
+ ```
371
+
372
+ ### Inspect (full flow)
373
+
374
+ ```bash
375
+ # TEI -> discovery -> releases -> components -> artifacts in one shot
376
+ tea-cli inspect "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
377
+
378
+ # Limit component resolution
379
+ tea-cli inspect --max-components 10 "urn:tei:purl:trust.sbomify.com:pkg:github/sbomify/sbomify"
380
+ ```
381
+
382
+ ### Search
383
+
384
+ ```bash
385
+ # Search products by PURL
386
+ tea-cli search-products --id-type PURL --id-value "pkg:github/sbomify/sbomify" \
387
+ --domain trust.sbomify.com
388
+
389
+ # Search product releases
390
+ tea-cli search-releases --id-type PURL --id-value "pkg:github/sbomify/sbomify" \
391
+ --domain trust.sbomify.com --page-size 50
392
+ ```
393
+
394
+ ### Products and releases
395
+
396
+ ```bash
397
+ # Get product details
398
+ tea-cli get-product <product-uuid> --domain trust.sbomify.com
399
+
400
+ # List releases for a product
401
+ tea-cli get-product-releases <product-uuid> --domain trust.sbomify.com
402
+
403
+ # Get a specific release (product or component)
404
+ tea-cli get-release <release-uuid> --domain trust.sbomify.com
405
+ tea-cli get-release <release-uuid> --component --domain trust.sbomify.com
406
+ ```
407
+
408
+ ### Components
409
+
410
+ ```bash
411
+ # Get component details
412
+ tea-cli get-component <component-uuid> --domain trust.sbomify.com
413
+
414
+ # List component releases
415
+ tea-cli get-component-releases <component-uuid> --domain trust.sbomify.com
416
+ ```
417
+
418
+ ### Collections and artifacts
419
+
420
+ ```bash
421
+ # Get latest collection (default) or specific version
422
+ tea-cli get-collection <release-uuid> --domain trust.sbomify.com
423
+ tea-cli get-collection <release-uuid> --version 3 --domain trust.sbomify.com
424
+
425
+ # List all collection versions
426
+ tea-cli list-collections <release-uuid> --domain trust.sbomify.com
427
+
428
+ # Get artifact metadata
429
+ tea-cli get-artifact <artifact-uuid> --domain trust.sbomify.com
430
+ ```
431
+
432
+ ### Download
433
+
434
+ ```bash
435
+ # Download an artifact with checksum verification
436
+ tea-cli download "https://cdn.example.com/sbom.json" ./sbom.json \
437
+ --checksum "SHA-256:abc123..." \
438
+ --domain trust.sbomify.com
439
+ ```
440
+
441
+ ### Lifecycle (CLE)
442
+
443
+ ```bash
444
+ # Get lifecycle events for different entity types
445
+ tea-cli get-cle <uuid> --entity product-release --domain trust.sbomify.com
446
+ tea-cli get-cle <uuid> --entity product --domain trust.sbomify.com
447
+ tea-cli get-cle <uuid> --entity component --domain trust.sbomify.com
448
+ tea-cli get-cle <uuid> --entity component-release --domain trust.sbomify.com
449
+ ```
450
+
451
+ ### Environment variables
452
+
453
+ | Variable | Description |
454
+ |----------|-------------|
455
+ | `TEA_BASE_URL` | TEA server base URL (alternative to `--base-url`) |
456
+ | `TEA_TOKEN` | Bearer token (alternative to `--token`) |
457
+ | `TEA_AUTH` | Basic auth as `USER:PASSWORD` (alternative to `--auth`) |
458
+
459
+ ### Shell completion
460
+
461
+ ```bash
462
+ # Bash (add to ~/.bashrc)
463
+ eval "$(_TEA_CLI_COMPLETE=bash_source tea-cli)"
464
+
465
+ # Zsh (add to ~/.zshrc)
466
+ eval "$(_TEA_CLI_COMPLETE=zsh_source tea-cli)"
467
+
468
+ # Fish (add to ~/.config/fish/completions/tea-cli.fish)
469
+ _TEA_CLI_COMPLETE=fish_source tea-cli | source
470
+ ```
471
+
472
+ ## Error handling
473
+
474
+ All exceptions inherit from `TeaError`:
475
+
476
+ ```python
477
+ from libtea.exceptions import TeaError, TeaNotFoundError, TeaChecksumError
478
+
479
+ try:
480
+ product = client.get_product("unknown-uuid")
481
+ except TeaNotFoundError as exc:
482
+ print(exc.error_type) # "OBJECT_UNKNOWN" or "OBJECT_NOT_SHAREABLE"
483
+ except TeaError:
484
+ print("Something went wrong")
485
+ ```
486
+
487
+ Exception hierarchy:
488
+
489
+ | Exception | When |
490
+ |-----------|------|
491
+ | `TeaConnectionError` | Network failure or timeout |
492
+ | `TeaAuthenticationError` | HTTP 401/403 |
493
+ | `TeaNotFoundError` | HTTP 404 (`.error_type` has the TEA error code) |
494
+ | `TeaRequestError` | Other HTTP 4xx |
495
+ | `TeaServerError` | HTTP 5xx |
496
+ | `TeaDiscoveryError` | Invalid TEI, `.well-known` failure, or no compatible endpoint |
497
+ | `TeaChecksumError` | Checksum mismatch (`.algorithm`, `.expected`, `.actual`) |
498
+ | `TeaValidationError` | Malformed server response |
499
+ | `TeaInsecureTransportWarning` | Warning emitted when using plaintext HTTP |
500
+
501
+ Using a bearer token over plaintext HTTP raises `ValueError` immediately — HTTPS is required for authenticated requests.
502
+
503
+ ## Requirements
504
+
505
+ - Python >= 3.11
506
+ - [requests](https://requests.readthedocs.io/) >= 2.32.4 for HTTP
507
+ - [Pydantic](https://docs.pydantic.dev/) >= 2.1.0 for data models
508
+ - [semver](https://python-semver.readthedocs.io/) >= 3.0.4 for version selection
509
+
510
+ Optional (for CLI): [click](https://click.palletsprojects.com/) >= 8.0, [rich](https://rich.readthedocs.io/) >= 13.0.0
511
+
512
+ ## Not yet supported
513
+
514
+ - Publisher API (spec is consumer-only in beta.2)
515
+ - Async client (planned for httpx migration)
516
+
517
+ ## Development
518
+
519
+ This project uses [uv](https://docs.astral.sh/uv/) for dependency management.
520
+
521
+ ```bash
522
+ uv sync # Install dependencies
523
+ uv run pytest # Run tests (with coverage)
524
+ uv run ruff check . # Lint
525
+ uv run ruff format --check . # Format check
526
+ uv build # Build wheel and sdist
527
+ ```
528
+
529
+ ## License
530
+
531
+ Apache 2.0 — see [LICENSE](LICENSE) for details.