Skip to main content

C2PA Python

Python bindings for the C2PA Content Authenticity Initiative (CAI) library

This library allows you to read and validate c2pa data in supported media files And to add signed manifests to supported media files.

Installation

pip install c2pa-python

Usage

Import

import c2pa-python as c2pa

Reading and Validating C2PA data in a file

Read any C2PA data from a given file

json_store = c2pa.verify_from_file_json("path/to/media_file.jpg", data_dir)

This will examine any supported media file for c2pa data and generate a JSON report of any data it finds. The report will include a validation_status field if any validation errors were found.

A media file may contain many manifests in a manifest store. The most recent manifest can be accessed by looking up the active_manifest field value in the manifests map.

If the optional data_dir is provided, any binary resources, such as thumbnails, icons and c2pa_data will be extracted into that directory. These files will be referenced by the identifier fields in the manifest store report.

Adding a Signed Manifest to a media file

The source is the media file which should receive new c2pa data. The destination will have a copy of the source with the data added. The manifest Json is a a JSON formatted string containing the data you want to add. (see: Generating SignerInfo for how to construct SignerInfo) The optional data_dir allows you to load resource files referenced from manifest_json identifiers. When building your manifest, any files referenced by identifier fields will be loaded relative to this path. This allows you to load thumbnails, icons and manifest data for ingredients

result = c2pa.add_manifest_to_file_json("path/to/source.jpg", "path/to/dest.jpg", manifest_json, sign_info, data_dir)

Generating SignerInfo

Set up the signer info from pem and key files.

certs = open("path/to/public_certs.pem","rb").read() prv_key = open("path/to/private_key.pem","rb").read()

Then create a new SignerInfo instance using those keys. You must specify the signing algorithm used and may optionally add a time stamp authority URL.

sign_info = c2pa.SignerInfo(certs, priv_key, "es256", "http://timestamp.digicert.com")

Creating a Manifest Json Definition File

The manifest json string defines the c2pa to add to the file.

manifest_json = json.dumps({
    "claim_generator": "python_test/0.1",
    "assertions": [
    {
      "label": "c2pa.training-mining",
      "data": {
        "entries": {
          "c2pa.ai_generative_training": { "use": "notAllowed" },
          "c2pa.ai_inference": { "use": "notAllowed" },
          "c2pa.ai_training": { "use": "notAllowed" },
          "c2pa.data_mining": { "use": "notAllowed" }
        }
      }
    }
  ]
 })

Development

It is best to set up a virtual environment for development and testing https://virtualenv.pypa.io/en/latest/installation.html

We use maturin for packaging Rust in Python. It can can be installed with pip

pip install maturin

You will also need to install uniffi bindgen and pytest for testing

pip install uniffi_bindgen

pip install -U pytest

pip install <path to.whl> --force-reinstall

Testing

pytest

Supported file formats

Extensions MIME type
avi video/msvideo, video/avi, application-msvideo
avif image/avif
c2pa application/x-c2pa-manifest-store
dng image/x-adobe-dng
heic image/heic
heif image/heif
jpg, jpeg image/jpeg
m4a audio/mp4
mp4 video/mp4, application/mp4
mov video/quicktime
png image/png
svg image/svg+xml
tif,tiff image/tiff
wav audio/x-wav
webp image/webp

License

This package is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

Note that some components and dependent crates are licensed under different terms; please check the license terms for each crate and component for details.

Contributions and feedback

We welcome contributions to this project. For information on contributing, providing feedback, and about ongoing work, see Contributing.

Release files for c2pa-python 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for c2pa-python 0.2.0
File Size Uploaded
c2pa_python-0.2.0.tar.gz 107.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for c2pa-python 0.2.0
File Interpreter ABI Platform
c2pa_python-0.2.0-py3-none-manylinux_2_31_aarch64.whl Python 3 none Linux glibc 2.31+ ARM64 Details
c2pa_python-0.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 8.7 MB

Release files / c2pa_python-0.2.0.tar.gz

Download URL c2pa_python-0.2.0.tar.gz
Size 107.9 kB
Tags Source
SHA-256 checksum
How to use checksums
95122cd156fda3539376802692bcbd26773f776f2f9536ad6a7230d7c0642fae
BLAKE2b-256 checksum
How to use checksums
14f376cd75a7e2af90fc03caf73d75030c5a71da35c4a97172f26bec519d345d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release files / c2pa_python-0.2.0-py3-none-manylinux_2_31_aarch64.whl

Download URL c2pa_python-0.2.0-py3-none-manylinux_2_31_aarch64.whl
Size 4.4 MB
Tags Linux glibc 2.31+ ARM64 Python 3
SHA-256 checksum
How to use checksums
96d1e6ae1b5279df6f5643da477c96f7c21e256fded44cb249eefb8c223b457d
BLAKE2b-256 checksum
How to use checksums
a91bf17554e7ef75afbb3d519ebfc6c9fb6e6f11fa7d5568551db597bae4a3ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release files / c2pa_python-0.2.0-py3-none-macosx_11_0_arm64.whl

Download URL c2pa_python-0.2.0-py3-none-macosx_11_0_arm64.whl
Size 4.2 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
18face8a672d217e0e768dc08f6e3956dc97eb1267421d3ea8c3574eeb62cf35
BLAKE2b-256 checksum
How to use checksums
705bb67438b50a6bc0dd8a7bfa6513047274ce2be648e6592654b2fe4eb84e16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.2.3

Release history Release notifications | RSS feed

0.37.8

8 release files

0.37.7

8 release files

0.37.6

8 release files

0.37.2

8 release files

0.37.1

8 release files

0.37.0

8 release files

0.36.0

8 release files

0.35.2

8 release files

0.35.1

8 release files

0.35.0

8 release files

0.34.0

8 release files

0.32.9

7 release files

0.32.8

7 release files

0.32.7

7 release files

0.32.4

7 release files

0.32.3

7 release files

0.30.0

7 release files

0.29.0

7 release files

0.28.0

7 release files

0.27.1

7 release files

0.27.0

7 release files

0.23.1

7 release files

0.23.0

7 release files

0.22.0

7 release files

0.21.0

7 release files

0.18.0

5 release files

0.17.0

5 release files

0.16.0

5 release files

0.15.0

5 release files

0.14.0

5 release files

0.13.0

5 release files

0.12.1

5 release files

0.12.0

5 release files

0.11.1

5 release files

0.11.0

5 release files

0.10.0

4 release files

0.9.0

6 release files

0.8.3

1 release file

0.8.0

6 release files

0.6.1

7 release files

0.6.0

7 release files

0.5.3

7 release files

0.5.2

7 release files

0.5.1

7 release files

0.5.0

7 release files

0.4.0

7 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

This release

0.2.0 This release

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page