API reference¶
Auto-generated from docstrings -- full signatures, parameter types, and defaults for the same Python API surface that page introduces narratively. Start there for how to use it; come here for the exact call signature.
Generator functions¶
pitloom.assemble.generate ¶
generate(
target: Path | str = ".",
*,
offline: bool | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
update_registry: bool | None = None,
) -> str
Smart unified entrypoint for generating SPDX 3 SBOMs across all target types.
Source code in pitloom/assemble/__init__.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
pitloom.assemble.generate_project_sbom ¶
generate_project_sbom(
project_target: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
project_metadata: ProjectMetadata | None = None,
pitloom_config: PitloomConfig | None = None,
registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
update_registry: bool | None = None,
) -> str
Generate a Source SPDX 3 SBOM for a Python project or sdist archive.
Source code in pitloom/assemble/_generators.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
pitloom.assemble.generate_wheel_sbom ¶
generate_wheel_sbom(
wheel_path: Path | str,
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
offline: bool | None = None,
update_registry: bool | None = None,
) -> str
Generate an Analyzed SPDX 3 SBOM for a built Python wheel.
Source code in pitloom/assemble/_generators.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
pitloom.assemble.generate_model_sbom ¶
generate_model_sbom(
source: Path | str,
*,
offline: bool | None = None,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
) -> str
Generate an Analyzed SPDX 3 AIBOM for a local model file or HF repository.
Source code in pitloom/assemble/_model_generator.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
pitloom.assemble.generate_env_sbom ¶
generate_env_sbom(
*,
output_path: Path | None = None,
creation_metadata: CreationMetadata | None = None,
pretty: bool | None = None,
describe_relationship: bool | None = None,
registry: str | Path | IdRegistry | None = None,
provenance: ProvenanceConfig | None = None,
offline: bool | None = None,
update_registry: bool | None = None,
) -> str
Generate a Deployed SPDX 3 SBOM for the current installed environment.
Source code in pitloom/assemble/_generators.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
Wheel embedding¶
pitloom.embed.embed_wheel_sbom ¶
embed_wheel_sbom(
wheel_path: Path | str,
*,
project_dir: Path | str | None = None,
pitloom_config: PitloomConfig | None = None,
sbom_path: Path | str | None = None,
output_path: Path | str | None = None,
sbom_basename: str | None = None,
creation_metadata: CreationMetadata | None = None,
registry: str | Path | IdRegistry | None = None,
overrides: ConfigOverrides | None = None,
) -> tuple[Path, str, str, tuple[str, ...], bool]
Generate and embed a PEP 770 SBOM into a built Python wheel.
Source code in pitloom/embed.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
pitloom.embed.embed_sbom_in_wheel ¶
embed_sbom_in_wheel(
wheel_path: Path | str,
sbom_content: str | bytes,
*,
sbom_filename: str | None = None,
) -> tuple[Path, str, tuple[str, ...], bool]
Embed an SPDX 3 SBOM into a built wheel archive (PEP 770).
Source code in pitloom/_embed_wheel.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
pitloom.embed.ConfigOverrides
dataclass
¶
ConfigOverrides(
provenance: ProvenanceConfig | None = None,
enrich: bool | None = None,
extract_file_header: bool | None = None,
content_type: bool | None = None,
content_type_method: str | None = None,
offline: bool | None = None,
)
Per-run overrides layered onto a project's [tool.pitloom] config.
Tracking decorator¶
loom.run is the Run class below (run = Run) -- use it as a
decorator or a context manager, as shown on the Python
API page.
pitloom.loom.Run ¶
Run(
output_file: str | Path,
pretty: bool = False,
creation_metadata: CreationMetadata | None = None,
registry: str | Path | IdRegistry | None = None,
)
Context manager and decorator for capturing SPDX fragments.
Each Run is a single recording session that weaves metadata about
a model and its datasets into an SBOM fragment.
Can be used as a context manager::
with loom.run("fragments/train.spdx3.json") as run:
run.set_model("my-model")
run.add_dataset("train.txt")
run.add_validation_dataset("valid.txt")
# ... training code ...
run.set_model_hyperparameters({"lr": "0.1", "epoch": "5"})
Or as a function decorator::
@loom.run("fragments/preprocess.spdx3.json")
def preprocess():
loom.add_input_dataset("rawdata/neg.txt")
loom.add_output_dataset("data/train.txt",
data_preprocessing=["tokenization"])
The fragment's SPDX CreationInfo is configurable on par with the CLI
and Hatchling build hook: pass a CreationMetadata to name a creator
(a person, organization, or automated agent), or override the tool,
timestamp, and comment. With none given, the fragment records the
SoftwareAgent "Pitloom" (createdBy) and Tool "Pitloom"
(createdUsing) of an unattended run::
loom.run(
"fragments/train.spdx3.json",
creation_metadata=CreationMetadata(
creators=[Creator(name="Alice", type="person")]
),
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_file
|
str | Path
|
Path to write the SBOM fragment to. |
required |
pretty
|
bool
|
Indent the JSON output with 2 spaces when |
False
|
creation_metadata
|
CreationMetadata | None
|
Creator, tool, timestamp, and comment overrides for
the fragment's |
None
|
registry
|
str | Path | IdRegistry | None
|
A |
None
|
Source code in pitloom/loom.py
88 89 90 91 92 93 94 95 96 97 98 99 | |
pitloom.loom.set_model ¶
set_model(
name: str,
model_type: str | None = None,
hyperparameters: dict[str, str] | None = None,
generated: bool | None = None,
) -> None
Set the name of the AI model being trained in the current run.
Source code in pitloom/loom.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
pitloom.loom.use_model ¶
use_model(
name: str,
model_type: str | None = None,
hyperparameters: dict[str, str] | None = None,
) -> None
Explicitly declare an AI model consumed by the current run (for inference).
Source code in pitloom/loom.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
pitloom.loom.set_model_hyperparameters ¶
set_model_hyperparameters(
hyperparameters: dict[str, str],
) -> None
Update the active model with hyperparameters captured after training.
Source code in pitloom/loom.py
171 172 173 174 175 176 177 178 | |
pitloom.loom.add_dataset ¶
add_dataset(name: str, dataset_type: str = 'text') -> None
Add a dataset utilized by the AI model in the current run.
Source code in pitloom/loom.py
181 182 183 184 185 186 187 188 | |
pitloom.loom.add_validation_dataset ¶
add_validation_dataset(
name: str, dataset_type: str = "text"
) -> None
Add a validation/test dataset in the current run.
Source code in pitloom/loom.py
191 192 193 194 195 196 197 198 199 | |
pitloom.loom.add_input_dataset ¶
add_input_dataset(
name: str, dataset_type: str = "text"
) -> None
Declare a raw/source dataset consumed by a preprocessing step.
Source code in pitloom/loom.py
202 203 204 205 206 207 208 209 210 | |
pitloom.loom.add_output_dataset ¶
add_output_dataset(
name: str,
dataset_type: str = "text",
data_preprocessing: list[str] | None = None,
input_datasets: list[str] | None = None,
) -> None
Declare a derived/processed dataset produced by a preprocessing step.
Source code in pitloom/loom.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
Creation metadata¶
pitloom.core.creation.CreationMetadata
dataclass
¶
CreationMetadata(
creators: list[Creator] = list(),
tools: list[Tool] | None = None,
creation_datetime: str | None = None,
creation_comment: str | None = None,
build_datetime: str | None = None,
)
Metadata describing who and what generated an SBOM.
Pitloom's own model for creation provenance -- distinct from, but
mapping onto, SPDX 3 CreationInfo: each creator becomes an Agent
in createdBy (Person, Organization, SoftwareAgent, or
the generic Agent -- see Creator.type), and each tool becomes
a Tool in createdUsing. When no creator is named, the
assembler records the automated SoftwareAgent "Pitloom" in
createdBy -- Pitloom acting on its own -- rather than inventing a
Person.
Attributes:
| Name | Type | Description |
|---|---|---|
creators |
list[Creator]
|
Named creators, in order. When empty (default), no named
creator is asserted and the assembler emits the
|
tools |
list[Tool] | None
|
Creation tools, in order. |
creation_datetime |
str | None
|
ISO 8601 string for the creation timestamp.
Full ISO forms are accepted (e.g. offsets and fractional
seconds). Pitloom preserves input precision internally and
normalises to SPDX 3 DateTime ( |
creation_comment |
str | None
|
Optional comment to include on the SPDX
|
build_datetime |
str | None
|
ISO 8601 string for when the artifact was built
(e.g. the moment the Hatchling hook fires). When set, the
assembler records it as |
pitloom.core.creation.Creator
dataclass
¶
Creator(
name: str,
type: str = "person",
email: str | None = None,
)
A single named creator, mapping onto an SPDX 3 Agent.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Display name of the person or organisation that initiated the SBOM generation. |
type |
str
|
Agent subclass: |
email |
str | None
|
E-mail address of the creator. Recorded as an |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
pitloom.core.creation.Tool
dataclass
¶
Tool(name: str)
A single creation tool, mapping onto an SPDX 3 Tool.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the tool. A tool literally named |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Provenance configuration¶
pitloom.core.provenance.ProvenanceConfig
dataclass
¶
ProvenanceConfig(
format: str = "both",
schema: str = DEFAULT_PROVENANCE_SCHEMA,
detail: str = "minimal",
preserve_source_metadata: str = "auto",
)
Configuration settings for SPDX 3 metadata provenance annotations.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
str
|
How to record metadata provenance ("annotation", "comment", "both"). |
schema |
str
|
Schema id for provenance Annotations. |
detail |
str
|
Provenance detail level ("minimal", "full"). |
preserve_source_metadata |
str
|
How to preserve source metadata ("auto", "always", "never"). |
ID registry¶
pitloom.ids.IdRegistry ¶
IdRegistry(
namespace: str,
files: dict[str, FileEntry] | None = None,
entities: dict[str, EntityEntry] | None = None,
path: Path | None = None,
)
A Loom ID registry: a stable file/entity -> SPDX ID registry, persisted as JSON.
Source code in pitloom/ids.py
62 63 64 65 66 67 68 69 70 71 72 | |
find
staticmethod
¶
find(start: Path | None = None) -> IdRegistry | None
Walk upward from start (default: cwd) looking for loom-ids.json.
Source code in pitloom/ids.py
113 114 115 116 117 118 119 120 121 122 123 124 125 | |
generate ¶
generate(paths: list[Path], project_root: Path) -> None
(Re-)index files under paths into this registry.
Source code in pitloom/ids.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
harvest ¶
harvest(object_set: SHACLObjectSet) -> tuple[int, int]
Harvest every named element in object_set into this registry.
Used both by :meth:import_sbom (after deserializing an existing
SBOM from disk) and by SBOM generation itself, directly on a
:class:~pitloom.export.spdx3_json.Spdx3JsonExporter's in-memory
object set -- no serialize/reparse round trip needed there, since
every element already carries its assigned spdxId.
Returns the number of (new_files, new_entities) added.
Source code in pitloom/ids.py
223 224 225 226 227 228 229 230 231 232 233 234 | |
import_sbom ¶
import_sbom(sbom_path: Path) -> None
Harvest ids from an existing SPDX 3 JSON-LD SBOM into this registry.
Source code in pitloom/ids.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
load
classmethod
¶
load(path: Path) -> IdRegistry
Load a registry from path.
Source code in pitloom/ids.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
lookup_entity ¶
lookup_entity(name: str, type_name: str) -> str | None
Return the registered spdxId for the named entity of type_name.
Source code in pitloom/ids.py
134 135 136 137 138 139 | |
lookup_file ¶
lookup_file(path: str, sha256: str) -> str | None
Return the registered spdxId for path.
Source code in pitloom/ids.py
127 128 129 130 131 132 | |
new
classmethod
¶
new(
project_name: str, path: Path | None = None
) -> IdRegistry
Create a fresh, empty registry with a freshly minted namespace.
Source code in pitloom/ids.py
74 75 76 77 78 | |
register_entity ¶
register_entity(name: str, type_name: str) -> str
Register (or reuse) a named entity and return its spdxId.
Source code in pitloom/ids.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
register_file ¶
register_file(path: str, sha256: str) -> str
Register (or refresh) a file entry and return its spdxId.
Source code in pitloom/ids.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
save ¶
save(path: Path | None = None) -> None
Write this registry as JSON to path.
Source code in pitloom/ids.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
pitloom.ids.resolve_registry ¶
resolve_registry(
project_dir: Path,
ids_file: str | Path | IdRegistry | None = None,
) -> IdRegistry | None
Resolve the registry a project build should consult.
Source code in pitloom/ids.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |