jpegtrust
Embed, extract, and verify JPEG Trust provenance metadata.
jpegtrust is a Python package for working with JPEG Trust provenance metadata based on the C2PA and JUMBF standards. It lets you sign JPEG and PNG images with a C2PA manifest, embed unsigned metadata, extract it back out, and verify images against configurable trust profiles.
embed_image does not sign. It writes the metadata as unsigned JSON. Its output has no Claim or Claim Signature, so it is not a Trust Record under ISO/DIS 21617-1. Use sign_image for signed output.
Installation
pip install jpegtrust
Optional extras:
| Extra | Needed for |
|---|---|
c2pa |
sign_image, jpegtrust sign, and reading signed files with the C2PA SDK |
crypto |
Certificate chain validation (jpegtrust.crypto) |
pip install 'jpegtrust[c2pa]'
Quick start
from jpegtrust import embed_image, extract_from_file, sign_image, verify_image, create_profile, save_profile
# Create a trust profile
profile = create_profile(template="newsroom", name="Wire Photo Policy")
save_profile(profile, "profile.yml")
# Sign an image (needs the c2pa extra)
assertions = {
"c2pa.actions.v2": {
"actions": [{
"action": "c2pa.created",
"digitalSourceType": "http://cv.iptc.org/newscodes/digitalsourcetype/digitalCapture",
}]
}
}
sign_image("photo.jpg", assertions, "signed.jpg", cert_chain="chain.pem", private_key="key.pem")
# Or embed unsigned metadata
embed_image("photo.jpg", "metadata.json", "labelled.jpg")
# Extract metadata
metadata = extract_from_file("signed.jpg")
# Verify against the profile
report = verify_image("signed.jpg", "profile.yml")
print(f"{report.status} | {report.score} | {report.passed_checks}/{report.total_checks}")
CLI
# Profile operations
jpegtrust profile list-templates
jpegtrust profile list-checks
jpegtrust profile create --template newsroom -o profile.yml
# Sign (needs the c2pa extra; ASSERTIONS is a JSON file with the assertion map)
jpegtrust sign photo.jpg assertions.json --cert chain.pem --key key.pem -o signed.jpg
jpegtrust sign photo.jpg assertions.json --cert chain.pem --key key.pem --tsa-url http://tsa.example/
# Embed unsigned metadata
jpegtrust embed photo.jpg metadata.json -o labelled.jpg
# Extract metadata
jpegtrust extract signed.jpg
jpegtrust extract signed.jpg -o metadata.json
# Verify
jpegtrust verify signed.jpg profile.yml
jpegtrust verify signed.jpg profile.yml --format json
# Batch operations
jpegtrust batch embed ./photos metadata.json -o ./signed
jpegtrust batch extract ./signed -o ./extracted
jpegtrust batch verify ./signed profile.yml
API reference
Signing
| Function | Description |
|---|---|
sign_image(image, assertions, output, cert_chain, private_key, alg="ES256", tsa_url=None, thumbnail=False) |
Sign a JPEG or PNG with one C2PA manifest that holds the assertion map. Needs the c2pa extra |
jpegtrust.sign.SigningError |
Raised for any input or signing problem. A subclass of ValueError |
Embedding (unsigned)
| Function | Description |
|---|---|
embed_image(image, metadata, output) |
Embed unsigned metadata from a file path or dict into a JPEG or PNG |
embed_metadata(image_bytes, metadata_dict) |
Embed unsigned metadata into raw JPEG or PNG bytes |
Extraction
| Function | Description |
|---|---|
extract_from_file(image) |
Extract and parse metadata from a JPEG or PNG file |
extract_metadata(image_bytes) |
Extract the raw JSON string from an unsigned JSON box |
Verification
| Function | Description |
|---|---|
verify(indicator, profile_yaml) |
Verify an indicator dict against a profile YAML string |
verify_image(image_path, profile_path) |
Extract + verify in one call |
Signing
sign_image signs an image with the C2PA SDK (c2pa-python). It takes:
- the input JPEG or PNG, which it does not change
- an assertion map
{label: data}, or the path of a JSON file that holds one. This is the same shape asdeclaration.assertionsin the metadata thatembed_imagetakes - the output path
- a PEM certificate chain, leaf first, and the PEM private key of the leaf certificate
- optional:
alg(ES256,ES384,ES512,PS256,PS384,PS512orED25519; it must match the key),tsa_url(an RFC 3161 time-stamp authority; an empty value means no time-stamp) andthumbnail(add the SDK's claim thumbnail; off by default)
The output holds one signed manifest: the assertions, a c2pa.hash.data hard binding that the SDK adds, a Claim and a Claim Signature. It holds no Trust Declaration.
sign_image raises SigningError, and leaves no file at the output path, when:
- the image already has a manifest. It does not add the old manifest as an ingredient
- the assertion map holds status fields (
signature_status,content_status,assertion_status,status) - the assertion map holds a label that the SDK writes itself (
c2pa.hash.*,c2pa.thumbnail.*) - the SDK reads the signed output back as invalid. For example, a
c2pa.createdaction needs adigitalSourceType - the SDK stores a label under another name. For example, the SDK stores
c2pa.actionsasc2pa.actions.v2, so usec2pa.actions.v2 - the output path is the input path, the output folder does not exist, or the key, certificate or assertion file cannot be read or used
Error messages name the key file's path but never hold any part of the key.
The validator in this repository gives signed output a scoped conformance pass when the root of the signing chain is a trust anchor. For tests and examples, validator/tests/fixtures/ holds public test keys (test-signing-cert.txt, test-signing-key.txt, root test-root-cert.txt). Anyone can sign with them, so do not use them for real work.
Where status fields come from
extract_from_file reads a signed file with the C2PA SDK when the c2pa extra is installed. The SDK computes the status fields (for example manifests[0].status.signature). For an unsigned JSON box, extract_from_file drops any status fields that the file supplies about itself, so an unsigned file fails the signature_chain and pixel_hash checks.
verify(indicator, profile_yaml) takes a dict and trusts it, including any status fields in it. Pass it only dicts from extract_from_file or from a source that you trust.
verify_image does not check the signer's certificate against trust anchors. Use the validator for signer trust and conformance.
Profiles
| Function | Description |
|---|---|
create_profile(template, name, issuer) |
Create a profile from a predefined template |
save_profile(profile, path) |
Save profile as YAML |
load_profile(path) |
Load profile YAML from file |
list_templates() |
List available templates and their checks |
list_checks() |
List all available check definitions |
Batch
| Function | Description |
|---|---|
batch_embed(input_dir, metadata, output_dir) |
Embed metadata into all images in a directory |
batch_extract(input_dir, output_dir) |
Extract metadata from all images |
batch_verify(input_dir, profile) |
Verify all images against a profile |
Templates
| Template | Checks | Use case |
|---|---|---|
newsroom |
All 9 checks | Wire photos, editorial verification |
insurance |
signature, timestamp, author, edit history, GPS, pixel hash | Claims photo validation |
creator |
signature, author, copyright, AI declaration, pixel hash | Artist authenticity |
ai-labelling |
signature, AI declaration, digital source type, AI labelling, edit history, pixel hash, data mining | AI labelling |
custom |
None (you pick) | Build your own |
Trust profiles
Trust profiles are multi-document YAML files that define verification rules. Each rule contains an expression evaluated against the image's Trust Indicator Set (ISO/DIS 21617-1 A.4). In that set, declaration is the Trust Declaration written when the asset was created, and manifests lists the other Trust Manifests with the active one first, so manifests[0] is the active manifest:
---
metadata:
name: "My Profile"
issuer: "My Organization"
date: "2025-01-01T00:00:00Z"
version: "1.0.0"
language: en
---
- id: signature_check
expression: >
manifests[0].status.signature == "claimSignature.validated"
report_text:
'true':
en: "Valid signature"
'false':
en: "No valid signature"
Verification report
report = verify_image("signed.jpg", "profile.yml")
report.status # "pass" | "warning" | "fail"
report.score # 0.0 - 1.0
report.verdict # "trusted" | "mostly_trusted" | "profile_mismatch"
report.passed # ["signature_chain", "pixel_hash", ...]
report.failed # ["gps_location", ...]
report.total_checks # 9
report.passed_checks # 7
report.c2pa # C2PA detection info
report.to_dict() # Full report as a dict
License
MIT
Metadata
Release files for jpegtrust 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jpegtrust-0.3.0.tar.gz | 2.5 MB | Without provenance | Details for jpegtrust-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jpegtrust-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for jpegtrust-0.3.0-py3-none-any.whl |
Total release size: 2.5 MB
Release files / jpegtrust-0.3.0.tar.gz
| Download URL | jpegtrust-0.3.0.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92e81c79ec07aab57fa67d7b026414f53eeccb1e1da113e9604e4d5b61e682df
|
|
BLAKE2b-256 checksum How to use checksums |
512708cf95e846c252c4b36f35ae683b2aa3c731296d313bbc0922d63a899470
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Release files / jpegtrust-0.3.0-py3-none-any.whl
| Download URL | jpegtrust-0.3.0-py3-none-any.whl |
|---|---|
| Size | 45.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b300bf03107beaf8025d78a0af7ac5cc80a002324905e0685da4c7f88c16f05
|
|
BLAKE2b-256 checksum How to use checksums |
5282099922c363df98c54fec0e6a1920fbbd191bb4514dda60a09a9e08153f2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.13
|
Security for jpegtrust 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.