API Reference & Usage
Complete reference for every function in the jpegtrust package. Each entry includes the full signature, parameter descriptions, return type, and working examples.
Embedding
Embed provenance metadata into JPEG images. The metadata is stored as a JUMBF box inside APP11 marker segments. Existing metadata is automatically stripped before re-embedding.
High-level function that reads an image file, loads metadata from a JSON file or dict, embeds it, and writes the result. This is the recommended way to embed metadata.
from jpegtrust import embed_image # From a JSON file embed_image("photo.jpg", "metadata.json", "signed.jpg") # From a Python dict metadata = { "@context": ["https://jpeg.org/jpegtrust/"], "declaration": { "claim": {"alg": "sha256"}, "assertions": {"c2pa.actions": {"actions": []}} } } embed_image("photo.jpg", metadata, "signed.jpg")
Low-level function that works with raw bytes. Use this when you already have image data in memory (e.g., from a web upload or stream).
from jpegtrust import embed_metadata with open("photo.jpg", "rb") as f: image_bytes = f.read() metadata = {"@context": ["https://jpeg.org/jpegtrust/"], ...} # Get bytes back result = embed_metadata(image_bytes, metadata) # Or write directly to disk embed_metadata(image_bytes, metadata, output_path="signed.jpg")
Extraction
Read provenance metadata from JPEG images. Supports both the JUMBF JSON format (from embed_image) and native C2PA binary manifests (via c2pa-python).
High-level extraction that tries two methods: first the JUMBF JSON box, then the c2pa-python SDK for real C2PA manifests. Returns a parsed indicator dict ready for verification.
from jpegtrust import extract_from_file indicator = extract_from_file("signed.jpg") if indicator is None: print("No metadata found") else: print(indicator["declaration"]["claim"]["alg"]) # "sha256" print(indicator["manifests"][0]["assertions"]) # {...}
Low-level extraction that works with raw bytes. Only reads the JUMBF JSON format (not native C2PA). Returns the raw JSON string.
import json from jpegtrust import extract_metadata with open("signed.jpg", "rb") as f: raw = extract_metadata(f.read()) if raw: data = json.loads(raw) print(json.dumps(data, indent=2))
Verification
Validate images against trust profiles. The verifier evaluates each check expression against the image metadata and produces a scored report.
High-level function that extracts metadata from an image and verifies it against a profile YAML file in one call. This is the easiest way to verify an image.
from jpegtrust import verify_image report = verify_image("signed.jpg", "policy.yml") print(f"Status: {report.status}") # "pass" | "warning" | "fail" print(f"Score: {report.score}") # 0.0 - 1.0 print(f"Verdict: {report.verdict}") # "trusted" | "mostly_trusted" | "profile_mismatch" print(f"Passed: {report.passed_checks}/{report.total_checks}") print(f"Failed: {report.failed}") # Convert to dict for JSON serialization result_dict = report.to_dict()
Low-level verification that takes an already-extracted indicator dict and a profile YAML string. Use this when you need control over extraction and profile loading separately.
from jpegtrust import verify, extract_from_file, load_profile # Step 1: extract the indicator indicator = extract_from_file("signed.jpg") # Step 2: load the profile YAML profile_yaml = load_profile("policy.yml") # Step 3: verify report = verify(indicator, profile_yaml) print(report.status, report.score)
Profiles
Trust profiles define what checks an image must pass. They are stored as multi-document YAML files. You can create them from templates, build custom ones, or load existing files.
Create a trust profile from a template or a custom list of check IDs. If check_ids is provided, it overrides the template.
from jpegtrust import create_profile, save_profile # From a template profile = create_profile(template="newsroom", name="AP Wire Photo Policy") save_profile(profile, "newsroom.yml") # Custom: pick specific checks profile = create_profile( check_ids=["signature_chain", "pixel_hash", "copyright"], name="Licensing Policy", issuer="My Platform", ) save_profile(profile, "licensing.yml")
Serialize a Profile object to YAML and write it to a file.
Read a profile YAML file and return its contents as a string. Use the result with verify().
Serialize a Profile object to a YAML string without writing to disk.
Get all available profile templates and their check IDs.
from jpegtrust import list_templates for name, check_ids in list_templates().items(): print(f"{name}: {len(check_ids)} checks") # Output: # newsroom: 11 checks # insurance: 6 checks # creator: 6 checks # ai-labelling: 7 checks # custom: 0 checks
Get all available check definitions with IDs, labels, levels, and expressions.
from jpegtrust import list_checks for check in list_checks(): print(f"{check.id:24s} [{check.level:8s}] {check.label}") # Output: # signature_chain [required] Signature chain # capture_timestamp [required] Capture timestamp # author_identity [required] Author identity # edit_history [required] Edit history # ai_declaration [required] AI declaration # gps_location [optional] GPS / location # copyright [optional] Copyright / licence # data_mining [optional] Data mining declaration # pixel_hash [required] Pixel hash binding # digital_source_type [required] Digital source type # ai_labelling [optional] AI labelling
Available checks reference
Batch operations
Process entire directories of images at once. All batch functions accept a glob pattern to filter files.
Embed the same metadata into all matching images in a directory.
from jpegtrust import batch_embed outputs = batch_embed("./photos", "metadata.json", "./signed") print(f"Embedded {len(outputs)} images") # With a custom pattern outputs = batch_embed("./photos", "metadata.json", "./signed", pattern="*.jpeg")
Extract metadata from all matching images. Optionally write each result as a .json file.
from jpegtrust import batch_extract # Just get the data results = batch_extract("./signed") for r in results: if r["metadata"]: print(f"{r['filename']}: has metadata") # Also write JSON files results = batch_extract("./signed", output_dir="./extracted")
Verify all matching images against a trust profile. Returns individual results and a summary.
import sys from jpegtrust import batch_verify result = batch_verify("./uploads", "policy.yml") summary = result["summary"] print(f"Total: {summary['total']}") print(f"Passed: {summary['passed']}") print(f"Failed: {summary['failed']}") # Use in CI: fail if any image doesn't pass if summary["failed"] > 0 or summary["errors"] > 0: sys.exit(1)
Data types
These dataclasses are returned by the API functions. Import them from jpegtrust._types if you need type annotations.
The result of a verification. Contains the status, score, verdict, and detailed results for each check.
A trust profile containing metadata and a list of checks.
Information about C2PA content credentials detected in the image.
CLI reference
The jpegtrust command-line tool provides access to all package features. Install with pip and the jpegtrust command becomes available.
Embed metadata into a single JPEG image.
jpegtrust embed <IMAGE> <METADATA> [-o OUTPUT] [--digital-source-type TYPE]
jpegtrust embed photo.jpg metadata.json -o signed.jpg
Extract metadata from a JPEG. Prints JSON to stdout or writes to a file.
jpegtrust extract <IMAGE> [-o OUTPUT]
# Print to terminal jpegtrust extract signed.jpg # Save to file jpegtrust extract signed.jpg -o metadata.json # Pipe to jq jpegtrust extract signed.jpg | jq '.manifests[0].status'
Verify an image against a trust profile.
jpegtrust verify <IMAGE> <PROFILE> [--format json|text]
# Human-readable jpegtrust verify signed.jpg policy.yml # JSON for scripting jpegtrust verify signed.jpg policy.yml --format json
Create a trust profile from a template or custom checks.
jpegtrust profile create [--template NAME] [--name NAME] [--issuer NAME] [--checks IDS] [-o FILE]
# From a template jpegtrust profile create --template newsroom -o newsroom.yml # Custom checks jpegtrust profile create --checks signature_chain,pixel_hash,copyright \ --name "My Policy" --issuer "My Org" -o custom.yml # Preview to stdout (don't save) jpegtrust profile create --template insurance
Show all available templates and their checks.
jpegtrust profile list-templates
Show all available check IDs with levels and labels.
jpegtrust profile list-checks
List all valid IPTC digital source types. AI-related types are marked with [AI].
jpegtrust profile list-source-types
Embed metadata into all images in a directory.
jpegtrust batch embed <INPUT_DIR> <METADATA> -o <OUTPUT_DIR> [--pattern GLOB]
jpegtrust batch embed ./photos metadata.json -o ./signed --pattern "*.jpeg"Extract metadata from all images in a directory.
jpegtrust batch extract <INPUT_DIR> [-o OUTPUT_DIR] [--pattern GLOB]
jpegtrust batch extract ./signed -o ./extracted
Verify all images in a directory against a profile.
jpegtrust batch verify <INPUT_DIR> <PROFILE> [--pattern GLOB] [--format json|text]
jpegtrust batch verify ./signed policy.yml --format json