libtea 0.1.0__tar.gz → 0.1.1__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.
- libtea-0.1.1/.github/dependabot.yml +18 -0
- libtea-0.1.1/.github/workflows/ci.yaml +21 -0
- libtea-0.1.1/.github/workflows/codeql.yaml +30 -0
- libtea-0.1.1/.github/workflows/pypi.yaml +60 -0
- {libtea-0.1.0 → libtea-0.1.1}/.gitignore +0 -6
- libtea-0.1.1/PKG-INFO +269 -0
- libtea-0.1.1/README.md +241 -0
- libtea-0.1.1/libtea/__init__.py +84 -0
- libtea-0.1.1/libtea/_http.py +257 -0
- libtea-0.1.1/libtea/client.py +393 -0
- libtea-0.1.1/libtea/discovery.py +224 -0
- libtea-0.1.1/libtea/exceptions.py +58 -0
- libtea-0.1.1/libtea/models.py +330 -0
- {libtea-0.1.0 → libtea-0.1.1}/pyproject.toml +11 -7
- libtea-0.1.1/tests/conftest.py +25 -0
- libtea-0.1.1/tests/test_client.py +469 -0
- libtea-0.1.1/tests/test_discovery.py +346 -0
- libtea-0.1.1/tests/test_download.py +106 -0
- libtea-0.1.1/tests/test_exceptions.py +75 -0
- libtea-0.1.1/tests/test_http.py +383 -0
- libtea-0.1.1/tests/test_integration.py +124 -0
- libtea-0.1.1/tests/test_models.py +358 -0
- libtea-0.1.1/tests/test_version.py +23 -0
- libtea-0.1.1/uv.lock +704 -0
- libtea-0.1.0/PKG-INFO +0 -62
- libtea-0.1.0/README.md +0 -36
- libtea-0.1.0/libtea/__init__.py +0 -5
- libtea-0.1.0/tests/test_version.py +0 -5
- {libtea-0.1.0 → libtea-0.1.1}/.pre-commit-config.yaml +0 -0
- {libtea-0.1.0 → libtea-0.1.1}/CLAUDE.md +0 -0
- {libtea-0.1.0 → libtea-0.1.1}/LICENSE +0 -0
- {libtea-0.1.0 → libtea-0.1.1}/libtea/py.typed +0 -0
- {libtea-0.1.0 → libtea-0.1.1}/tests/__init__.py +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: "github-actions"
|
|
4
|
+
directory: "/"
|
|
5
|
+
schedule:
|
|
6
|
+
interval: "weekly"
|
|
7
|
+
groups:
|
|
8
|
+
github-actions:
|
|
9
|
+
patterns:
|
|
10
|
+
- "*"
|
|
11
|
+
- package-ecosystem: "uv"
|
|
12
|
+
directory: "/"
|
|
13
|
+
schedule:
|
|
14
|
+
interval: "weekly"
|
|
15
|
+
groups:
|
|
16
|
+
uv:
|
|
17
|
+
patterns:
|
|
18
|
+
- "*"
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
16
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
17
|
+
- run: uv python install ${{ matrix.python-version }}
|
|
18
|
+
- run: uv sync
|
|
19
|
+
- run: uv run ruff check .
|
|
20
|
+
- run: uv run ruff format --check .
|
|
21
|
+
- run: uv run pytest --cov=libtea --cov-report=term-missing
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: CodeQL
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
schedule:
|
|
8
|
+
- cron: "0 6 * * 1"
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
analyze:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
security-events: write
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
language: [python]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
20
|
+
|
|
21
|
+
- name: Initialize CodeQL
|
|
22
|
+
uses: github/codeql-action/init@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
23
|
+
with:
|
|
24
|
+
languages: ${{ matrix.language }}
|
|
25
|
+
|
|
26
|
+
- name: Autobuild
|
|
27
|
+
uses: github/codeql-action/autobuild@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
28
|
+
|
|
29
|
+
- name: Perform CodeQL Analysis
|
|
30
|
+
uses: github/codeql-action/analyze@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: Build and Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build-and-publish-testpypi:
|
|
12
|
+
if: github.event_name == 'push'
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
environment:
|
|
15
|
+
name: testpypi
|
|
16
|
+
url: https://test.pypi.org/p/libtea
|
|
17
|
+
permissions:
|
|
18
|
+
id-token: write
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
21
|
+
|
|
22
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
23
|
+
|
|
24
|
+
- name: Determine version
|
|
25
|
+
id: version
|
|
26
|
+
run: |
|
|
27
|
+
BASE_VERSION=$(grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
|
|
28
|
+
DEV_VERSION="${BASE_VERSION}.dev${GITHUB_RUN_NUMBER}"
|
|
29
|
+
echo "version=${DEV_VERSION}" >> "$GITHUB_OUTPUT"
|
|
30
|
+
|
|
31
|
+
- name: Set dev version
|
|
32
|
+
run: |
|
|
33
|
+
sed -i "s/^version = .*/version = \"${{ steps.version.outputs.version }}\"/" pyproject.toml
|
|
34
|
+
|
|
35
|
+
- name: Build package
|
|
36
|
+
run: uv build
|
|
37
|
+
|
|
38
|
+
- name: Publish to TestPyPI
|
|
39
|
+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
|
40
|
+
with:
|
|
41
|
+
repository-url: https://test.pypi.org/legacy/
|
|
42
|
+
|
|
43
|
+
build-and-publish-pypi:
|
|
44
|
+
if: github.event_name == 'release'
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
environment:
|
|
47
|
+
name: pypi
|
|
48
|
+
url: https://pypi.org/p/libtea
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
53
|
+
|
|
54
|
+
- uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
|
|
55
|
+
|
|
56
|
+
- name: Build package
|
|
57
|
+
run: uv build
|
|
58
|
+
|
|
59
|
+
- name: Publish to PyPI
|
|
60
|
+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
|
@@ -94,12 +94,6 @@ ipython_config.py
|
|
|
94
94
|
# install all needed dependencies.
|
|
95
95
|
#Pipfile.lock
|
|
96
96
|
|
|
97
|
-
# UV
|
|
98
|
-
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
-
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
-
# commonly ignored for libraries.
|
|
101
|
-
uv.lock
|
|
102
|
-
|
|
103
97
|
# poetry
|
|
104
98
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
99
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
libtea-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libtea
|
|
3
|
+
Version: 0.1.1
|
|
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.12.0
|
|
26
|
+
Requires-Dist: requests<3,>=2.32.0
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# libtea
|
|
30
|
+
|
|
31
|
+
[](https://github.com/sbomify/py-libtea/actions/workflows/ci.yaml)
|
|
32
|
+
[](https://pypi.org/project/libtea/)
|
|
33
|
+
[](https://pypi.org/project/libtea/)
|
|
34
|
+
[](https://github.com/sbomify/py-libtea/blob/master/LICENSE)
|
|
35
|
+
|
|
36
|
+
Python client library for the [Transparency Exchange API (TEA)](https://transparency.exchange/) v0.3.0-beta.2.
|
|
37
|
+
|
|
38
|
+
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.
|
|
39
|
+
|
|
40
|
+
**Specification:** [Ecma TC54-TG1](https://tc54.org/tea/) | [OpenAPI spec](https://github.com/CycloneDX/transparency-exchange-api)
|
|
41
|
+
|
|
42
|
+
> **Status**: Alpha — API is subject to change.
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
- Auto-discovery via `.well-known/tea` and TEI URNs
|
|
47
|
+
- Products, components, releases, and versioned collections
|
|
48
|
+
- Search by PURL, CPE, or TEI identifier
|
|
49
|
+
- Artifact download with on-the-fly checksum verification (MD5 through BLAKE2b)
|
|
50
|
+
- Typed Pydantic v2 models with full camelCase/snake_case conversion
|
|
51
|
+
- Structured exception hierarchy with error context
|
|
52
|
+
- Bearer token isolation — tokens are never sent to artifact download hosts
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install libtea
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from libtea import TeaClient
|
|
64
|
+
|
|
65
|
+
# Auto-discover from a domain's .well-known/tea
|
|
66
|
+
with TeaClient.from_well_known("example.com", token="your-bearer-token") as client:
|
|
67
|
+
# Browse a product
|
|
68
|
+
product = client.get_product("product-uuid")
|
|
69
|
+
print(product.name)
|
|
70
|
+
|
|
71
|
+
# Get a component release with its latest collection
|
|
72
|
+
cr = client.get_component_release("release-uuid")
|
|
73
|
+
for artifact in cr.latest_collection.artifacts:
|
|
74
|
+
print(artifact.name, artifact.type)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Or connect directly to a known endpoint:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
client = TeaClient(
|
|
81
|
+
base_url="https://api.example.com/tea/v0.3.0-beta.2",
|
|
82
|
+
token="your-bearer-token",
|
|
83
|
+
timeout=30.0,
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Using `from_well_known`, you can also override the spec version and timeout:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
client = TeaClient.from_well_known(
|
|
91
|
+
"example.com",
|
|
92
|
+
token="your-bearer-token",
|
|
93
|
+
timeout=15.0,
|
|
94
|
+
version="0.3.0-beta.2", # default
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
### Search
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
with TeaClient.from_well_known("example.com") as client:
|
|
104
|
+
# Search by PURL
|
|
105
|
+
results = client.search_products("PURL", "pkg:pypi/requests")
|
|
106
|
+
for product in results.results:
|
|
107
|
+
print(product.name, product.uuid)
|
|
108
|
+
|
|
109
|
+
# Search product releases (with pagination)
|
|
110
|
+
releases = client.search_product_releases(
|
|
111
|
+
"PURL", "pkg:pypi/requests@2.31.0",
|
|
112
|
+
page_offset=0, page_size=100,
|
|
113
|
+
)
|
|
114
|
+
print(releases.total_results)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Products and releases
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
with TeaClient.from_well_known("example.com") as client:
|
|
121
|
+
product = client.get_product("product-uuid")
|
|
122
|
+
print(product.name, product.identifiers)
|
|
123
|
+
|
|
124
|
+
releases = client.get_product_releases("product-uuid", page_size=25)
|
|
125
|
+
for release in releases.results:
|
|
126
|
+
print(release.version, release.created_date)
|
|
127
|
+
|
|
128
|
+
# Single product release
|
|
129
|
+
pr = client.get_product_release("release-uuid")
|
|
130
|
+
print(pr.version, pr.components)
|
|
131
|
+
|
|
132
|
+
# Product release collections
|
|
133
|
+
latest = client.get_product_release_collection_latest("release-uuid")
|
|
134
|
+
all_versions = client.get_product_release_collections("release-uuid")
|
|
135
|
+
specific = client.get_product_release_collection("release-uuid", 3)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Components
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
142
|
+
component = client.get_component("component-uuid")
|
|
143
|
+
releases = client.get_component_releases("component-uuid")
|
|
144
|
+
|
|
145
|
+
# Get a component release with its latest collection
|
|
146
|
+
cr = client.get_component_release("release-uuid")
|
|
147
|
+
print(cr.release.version, len(cr.latest_collection.artifacts))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Collections and artifacts
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
154
|
+
collection = client.get_component_release_collection_latest("release-uuid")
|
|
155
|
+
for artifact in collection.artifacts:
|
|
156
|
+
print(artifact.name, artifact.type)
|
|
157
|
+
|
|
158
|
+
# All collection versions for a component release
|
|
159
|
+
all_versions = client.get_component_release_collections("release-uuid")
|
|
160
|
+
|
|
161
|
+
# Specific collection version
|
|
162
|
+
collection_v3 = client.get_component_release_collection("release-uuid", 3)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Downloading artifacts with checksum verification
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from pathlib import Path
|
|
169
|
+
|
|
170
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
171
|
+
artifact = client.get_artifact("artifact-uuid")
|
|
172
|
+
fmt = artifact.formats[0]
|
|
173
|
+
|
|
174
|
+
# Downloads and verifies checksums on-the-fly; returns the dest path
|
|
175
|
+
path = client.download_artifact(
|
|
176
|
+
fmt.url,
|
|
177
|
+
Path("sbom.json"),
|
|
178
|
+
verify_checksums=fmt.checksums,
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
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).
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
186
|
+
### Discovery
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from libtea.discovery import parse_tei, fetch_well_known, select_endpoint
|
|
190
|
+
|
|
191
|
+
# Parse a TEI URN
|
|
192
|
+
tei_type, domain, identifier = parse_tei(
|
|
193
|
+
"urn:tei:purl:cyclonedx.org:pkg:pypi/cyclonedx-python-lib@8.4.0"
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
# Low-level: fetch and select an endpoint manually
|
|
197
|
+
well_known = fetch_well_known("example.com")
|
|
198
|
+
endpoint = select_endpoint(well_known, "0.3.0-beta.2")
|
|
199
|
+
print(endpoint.url, endpoint.priority)
|
|
200
|
+
|
|
201
|
+
# Discover product releases by TEI
|
|
202
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
203
|
+
results = client.discover("urn:tei:uuid:example.com:d4d9f54a-abcf-11ee-ac79-1a52914d44b")
|
|
204
|
+
for info in results:
|
|
205
|
+
print(info.product_release_uuid, info.servers)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Supported TEI types: `uuid`, `purl`, `hash`, `swid`, `eanupc`, `gtin`, `asin`, `udi`.
|
|
209
|
+
|
|
210
|
+
## Error handling
|
|
211
|
+
|
|
212
|
+
All exceptions inherit from `TeaError`:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from libtea.exceptions import TeaError, TeaNotFoundError, TeaChecksumError
|
|
216
|
+
|
|
217
|
+
try:
|
|
218
|
+
product = client.get_product("unknown-uuid")
|
|
219
|
+
except TeaNotFoundError as exc:
|
|
220
|
+
print(exc.error_type) # "OBJECT_UNKNOWN" or "OBJECT_NOT_SHAREABLE"
|
|
221
|
+
except TeaError:
|
|
222
|
+
print("Something went wrong")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Exception hierarchy:
|
|
226
|
+
|
|
227
|
+
| Exception | When |
|
|
228
|
+
|-----------|------|
|
|
229
|
+
| `TeaConnectionError` | Network failure or timeout |
|
|
230
|
+
| `TeaAuthenticationError` | HTTP 401/403 |
|
|
231
|
+
| `TeaNotFoundError` | HTTP 404 (`.error_type` has the TEA error code) |
|
|
232
|
+
| `TeaRequestError` | Other HTTP 4xx |
|
|
233
|
+
| `TeaServerError` | HTTP 5xx |
|
|
234
|
+
| `TeaDiscoveryError` | Invalid TEI, `.well-known` failure, or no compatible endpoint |
|
|
235
|
+
| `TeaChecksumError` | Checksum mismatch (`.algorithm`, `.expected`, `.actual`) |
|
|
236
|
+
| `TeaValidationError` | Malformed server response |
|
|
237
|
+
| `TeaInsecureTransportWarning` | Warning emitted when using plaintext HTTP |
|
|
238
|
+
|
|
239
|
+
Using a bearer token over plaintext HTTP raises `ValueError` immediately — HTTPS is required for authenticated requests.
|
|
240
|
+
|
|
241
|
+
## Requirements
|
|
242
|
+
|
|
243
|
+
- Python >= 3.11
|
|
244
|
+
- [requests](https://requests.readthedocs.io/) >= 2.31.0 for HTTP
|
|
245
|
+
- [Pydantic](https://docs.pydantic.dev/) >= 2.1.0 for data models
|
|
246
|
+
|
|
247
|
+
## Not yet supported
|
|
248
|
+
|
|
249
|
+
- Publisher API (spec is consumer-only in beta.2)
|
|
250
|
+
- Async client
|
|
251
|
+
- CLE (Common Lifecycle Enumeration) endpoints
|
|
252
|
+
- Mutual TLS (mTLS) authentication
|
|
253
|
+
- Endpoint failover with retry
|
|
254
|
+
|
|
255
|
+
## Development
|
|
256
|
+
|
|
257
|
+
This project uses [uv](https://docs.astral.sh/uv/) for dependency management.
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
uv sync # Install dependencies
|
|
261
|
+
uv run pytest # Run tests (with coverage)
|
|
262
|
+
uv run ruff check . # Lint
|
|
263
|
+
uv run ruff format --check . # Format check
|
|
264
|
+
uv build # Build wheel and sdist
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
Apache 2.0 — see [LICENSE](LICENSE) for details.
|
libtea-0.1.1/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# libtea
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sbomify/py-libtea/actions/workflows/ci.yaml)
|
|
4
|
+
[](https://pypi.org/project/libtea/)
|
|
5
|
+
[](https://pypi.org/project/libtea/)
|
|
6
|
+
[](https://github.com/sbomify/py-libtea/blob/master/LICENSE)
|
|
7
|
+
|
|
8
|
+
Python client library for the [Transparency Exchange API (TEA)](https://transparency.exchange/) v0.3.0-beta.2.
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
**Specification:** [Ecma TC54-TG1](https://tc54.org/tea/) | [OpenAPI spec](https://github.com/CycloneDX/transparency-exchange-api)
|
|
13
|
+
|
|
14
|
+
> **Status**: Alpha — API is subject to change.
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- Auto-discovery via `.well-known/tea` and TEI URNs
|
|
19
|
+
- Products, components, releases, and versioned collections
|
|
20
|
+
- Search by PURL, CPE, or TEI identifier
|
|
21
|
+
- Artifact download with on-the-fly checksum verification (MD5 through BLAKE2b)
|
|
22
|
+
- Typed Pydantic v2 models with full camelCase/snake_case conversion
|
|
23
|
+
- Structured exception hierarchy with error context
|
|
24
|
+
- Bearer token isolation — tokens are never sent to artifact download hosts
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install libtea
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick start
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from libtea import TeaClient
|
|
36
|
+
|
|
37
|
+
# Auto-discover from a domain's .well-known/tea
|
|
38
|
+
with TeaClient.from_well_known("example.com", token="your-bearer-token") as client:
|
|
39
|
+
# Browse a product
|
|
40
|
+
product = client.get_product("product-uuid")
|
|
41
|
+
print(product.name)
|
|
42
|
+
|
|
43
|
+
# Get a component release with its latest collection
|
|
44
|
+
cr = client.get_component_release("release-uuid")
|
|
45
|
+
for artifact in cr.latest_collection.artifacts:
|
|
46
|
+
print(artifact.name, artifact.type)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or connect directly to a known endpoint:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
client = TeaClient(
|
|
53
|
+
base_url="https://api.example.com/tea/v0.3.0-beta.2",
|
|
54
|
+
token="your-bearer-token",
|
|
55
|
+
timeout=30.0,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Using `from_well_known`, you can also override the spec version and timeout:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
client = TeaClient.from_well_known(
|
|
63
|
+
"example.com",
|
|
64
|
+
token="your-bearer-token",
|
|
65
|
+
timeout=15.0,
|
|
66
|
+
version="0.3.0-beta.2", # default
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
### Search
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
with TeaClient.from_well_known("example.com") as client:
|
|
76
|
+
# Search by PURL
|
|
77
|
+
results = client.search_products("PURL", "pkg:pypi/requests")
|
|
78
|
+
for product in results.results:
|
|
79
|
+
print(product.name, product.uuid)
|
|
80
|
+
|
|
81
|
+
# Search product releases (with pagination)
|
|
82
|
+
releases = client.search_product_releases(
|
|
83
|
+
"PURL", "pkg:pypi/requests@2.31.0",
|
|
84
|
+
page_offset=0, page_size=100,
|
|
85
|
+
)
|
|
86
|
+
print(releases.total_results)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Products and releases
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
with TeaClient.from_well_known("example.com") as client:
|
|
93
|
+
product = client.get_product("product-uuid")
|
|
94
|
+
print(product.name, product.identifiers)
|
|
95
|
+
|
|
96
|
+
releases = client.get_product_releases("product-uuid", page_size=25)
|
|
97
|
+
for release in releases.results:
|
|
98
|
+
print(release.version, release.created_date)
|
|
99
|
+
|
|
100
|
+
# Single product release
|
|
101
|
+
pr = client.get_product_release("release-uuid")
|
|
102
|
+
print(pr.version, pr.components)
|
|
103
|
+
|
|
104
|
+
# Product release collections
|
|
105
|
+
latest = client.get_product_release_collection_latest("release-uuid")
|
|
106
|
+
all_versions = client.get_product_release_collections("release-uuid")
|
|
107
|
+
specific = client.get_product_release_collection("release-uuid", 3)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Components
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
114
|
+
component = client.get_component("component-uuid")
|
|
115
|
+
releases = client.get_component_releases("component-uuid")
|
|
116
|
+
|
|
117
|
+
# Get a component release with its latest collection
|
|
118
|
+
cr = client.get_component_release("release-uuid")
|
|
119
|
+
print(cr.release.version, len(cr.latest_collection.artifacts))
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Collections and artifacts
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
126
|
+
collection = client.get_component_release_collection_latest("release-uuid")
|
|
127
|
+
for artifact in collection.artifacts:
|
|
128
|
+
print(artifact.name, artifact.type)
|
|
129
|
+
|
|
130
|
+
# All collection versions for a component release
|
|
131
|
+
all_versions = client.get_component_release_collections("release-uuid")
|
|
132
|
+
|
|
133
|
+
# Specific collection version
|
|
134
|
+
collection_v3 = client.get_component_release_collection("release-uuid", 3)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Downloading artifacts with checksum verification
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from pathlib import Path
|
|
141
|
+
|
|
142
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
143
|
+
artifact = client.get_artifact("artifact-uuid")
|
|
144
|
+
fmt = artifact.formats[0]
|
|
145
|
+
|
|
146
|
+
# Downloads and verifies checksums on-the-fly; returns the dest path
|
|
147
|
+
path = client.download_artifact(
|
|
148
|
+
fmt.url,
|
|
149
|
+
Path("sbom.json"),
|
|
150
|
+
verify_checksums=fmt.checksums,
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
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).
|
|
155
|
+
|
|
156
|
+
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.
|
|
157
|
+
|
|
158
|
+
### Discovery
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from libtea.discovery import parse_tei, fetch_well_known, select_endpoint
|
|
162
|
+
|
|
163
|
+
# Parse a TEI URN
|
|
164
|
+
tei_type, domain, identifier = parse_tei(
|
|
165
|
+
"urn:tei:purl:cyclonedx.org:pkg:pypi/cyclonedx-python-lib@8.4.0"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Low-level: fetch and select an endpoint manually
|
|
169
|
+
well_known = fetch_well_known("example.com")
|
|
170
|
+
endpoint = select_endpoint(well_known, "0.3.0-beta.2")
|
|
171
|
+
print(endpoint.url, endpoint.priority)
|
|
172
|
+
|
|
173
|
+
# Discover product releases by TEI
|
|
174
|
+
with TeaClient(base_url="https://api.example.com/tea/v0.3.0-beta.2") as client:
|
|
175
|
+
results = client.discover("urn:tei:uuid:example.com:d4d9f54a-abcf-11ee-ac79-1a52914d44b")
|
|
176
|
+
for info in results:
|
|
177
|
+
print(info.product_release_uuid, info.servers)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Supported TEI types: `uuid`, `purl`, `hash`, `swid`, `eanupc`, `gtin`, `asin`, `udi`.
|
|
181
|
+
|
|
182
|
+
## Error handling
|
|
183
|
+
|
|
184
|
+
All exceptions inherit from `TeaError`:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from libtea.exceptions import TeaError, TeaNotFoundError, TeaChecksumError
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
product = client.get_product("unknown-uuid")
|
|
191
|
+
except TeaNotFoundError as exc:
|
|
192
|
+
print(exc.error_type) # "OBJECT_UNKNOWN" or "OBJECT_NOT_SHAREABLE"
|
|
193
|
+
except TeaError:
|
|
194
|
+
print("Something went wrong")
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Exception hierarchy:
|
|
198
|
+
|
|
199
|
+
| Exception | When |
|
|
200
|
+
|-----------|------|
|
|
201
|
+
| `TeaConnectionError` | Network failure or timeout |
|
|
202
|
+
| `TeaAuthenticationError` | HTTP 401/403 |
|
|
203
|
+
| `TeaNotFoundError` | HTTP 404 (`.error_type` has the TEA error code) |
|
|
204
|
+
| `TeaRequestError` | Other HTTP 4xx |
|
|
205
|
+
| `TeaServerError` | HTTP 5xx |
|
|
206
|
+
| `TeaDiscoveryError` | Invalid TEI, `.well-known` failure, or no compatible endpoint |
|
|
207
|
+
| `TeaChecksumError` | Checksum mismatch (`.algorithm`, `.expected`, `.actual`) |
|
|
208
|
+
| `TeaValidationError` | Malformed server response |
|
|
209
|
+
| `TeaInsecureTransportWarning` | Warning emitted when using plaintext HTTP |
|
|
210
|
+
|
|
211
|
+
Using a bearer token over plaintext HTTP raises `ValueError` immediately — HTTPS is required for authenticated requests.
|
|
212
|
+
|
|
213
|
+
## Requirements
|
|
214
|
+
|
|
215
|
+
- Python >= 3.11
|
|
216
|
+
- [requests](https://requests.readthedocs.io/) >= 2.31.0 for HTTP
|
|
217
|
+
- [Pydantic](https://docs.pydantic.dev/) >= 2.1.0 for data models
|
|
218
|
+
|
|
219
|
+
## Not yet supported
|
|
220
|
+
|
|
221
|
+
- Publisher API (spec is consumer-only in beta.2)
|
|
222
|
+
- Async client
|
|
223
|
+
- CLE (Common Lifecycle Enumeration) endpoints
|
|
224
|
+
- Mutual TLS (mTLS) authentication
|
|
225
|
+
- Endpoint failover with retry
|
|
226
|
+
|
|
227
|
+
## Development
|
|
228
|
+
|
|
229
|
+
This project uses [uv](https://docs.astral.sh/uv/) for dependency management.
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
uv sync # Install dependencies
|
|
233
|
+
uv run pytest # Run tests (with coverage)
|
|
234
|
+
uv run ruff check . # Lint
|
|
235
|
+
uv run ruff format --check . # Format check
|
|
236
|
+
uv build # Build wheel and sdist
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
Apache 2.0 — see [LICENSE](LICENSE) for details.
|