Skip to main content

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

Project description

C2PA Python library

The c2pa-python repository provides a Python library that can:

  • Read and validate C2PA manifest data from media files in supported formats.
  • Create and sign manifest data, and attach it to media files in supported formats.

Features:

  • Create and sign C2PA manifests using various signing algorithms.
  • Verify C2PA manifests and extract metadata.
  • Add assertions and ingredients to assets.
  • Examples and unit tests to demonstrate usage.

Prerequisites

This library requires Python version 3.10+.

Package installation

Install the c2pa-python package from PyPI by running:

pip install c2pa-python

To use the module in Python code, import the module like this:

import c2pa

Building from local c2pa-rs sources

Using a virtual environment with local builds

The make targets honor an active virtualenv. Create a virtual environment ./.venv and activate it before running them so commands use the project interpreter rather than the global Python interpreter:

make create-venv && source .venv/bin/activate

Build steps

By default the build downloads a prebuilt native library from a c2pa-rs release. To test the Python bindings against a local, unreleased c2pa-rs checkout, you can instead build the native library from source.

Prerequisites:

Point C2PA_RS_PATH at your c2pa-rs checkout and run the build-from-source target:

export C2PA_RS_PATH=/path/to/c2pa-rs
make build-from-source C2PA_RS_PATH=$C2PA_RS_PATH

This does a clean build of the c2pa-c-ffi crate (with the file_io feature, which the Python wrapper requires), stages the resulting library under both artifacts/ and src/c2pa/libs/, and installs the package in editable mode, replacing any prebuilt artifacts from make download-native-artifacts. The release profile is used by default; to build the debug profile instead, pass EXTRA_BUILD_ARGS="--debug":

make build-from-source C2PA_RS_PATH=$C2PA_RS_PATH EXTRA_BUILD_ARGS="--debug"

Note on targets for macOS

On macOS this produces a universal (arm64+x86_64) library by default, which requires both Rust targets:

rustup target add aarch64-apple-darwin x86_64-apple-darwin

To build a single-architecture library instead, set C2PA_LIBS_PLATFORM to a specific platform (for example aarch64-apple-darwin).

Examples

See the examples directory for some helpful examples:

  • examples/read.py shows how to read and verify an asset with a C2PA manifest.
  • examples/sign.py shows how to sign and verify an asset with a C2PA manifest.
  • examples/training.py demonstrates how to add a "Do Not Train" assertion to an asset and verify it.

API reference documentation

Documentation is published at github.io/c2pa-python/api/c2pa.

To build documentation locally, refer to this section in Contributing to the project.

Contributing

Contributions are welcome! For more information, see Contributing to the project.

License

This project is licensed under the Apache License 2.0 and the MIT License. See the LICENSE-MIT and LICENSE-APACHE files for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2pa_python-0.34.0.tar.gz (82.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

c2pa_python-0.34.0-py3-none-win_arm64.whl (87.1 MB view details)

Uploaded Python 3Windows ARM64

c2pa_python-0.34.0-py3-none-win_amd64.whl (89.6 MB view details)

Uploaded Python 3Windows x86-64

c2pa_python-0.34.0-py3-none-manylinux_2_28_x86_64.whl (15.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

c2pa_python-0.34.0-py3-none-manylinux_2_28_aarch64.whl (14.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

c2pa_python-0.34.0-py3-none-macosx_11_0_arm64.whl (14.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

c2pa_python-0.34.0-py3-none-macosx_10_9_x86_64.whl (14.9 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

c2pa_python-0.34.0-py3-none-macosx_10_9_universal2.whl (16.5 MB view details)

Uploaded Python 3macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file c2pa_python-0.34.0.tar.gz.

File metadata

  • Download URL: c2pa_python-0.34.0.tar.gz
  • Upload date:
  • Size: 82.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for c2pa_python-0.34.0.tar.gz
Algorithm Hash digest
SHA256 54445f4ba08832a5856f02188bf62779d44ee5ad0e62312e9f772f5bf244420f
MD5 169aecdbe54d29c64b05b0f69995547f
BLAKE2b-256 41446ef4c0a391faa5fb935284fc016d48f24db6930ba3b1735d90a0a64db1eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0.tar.gz:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: c2pa_python-0.34.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 87.1 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for c2pa_python-0.34.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 6927c789b50316232fa94dbc1dc2c812aa247a49d97f47fde9bbe9f69f203806
MD5 69d23faec484640d188dd74291993a36
BLAKE2b-256 ea4a298008a78633b1de5947f4b1dc55704637805790b240b718eacf64e390ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-win_arm64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: c2pa_python-0.34.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 89.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for c2pa_python-0.34.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 868b5a33d39151902d84065102da2d565e9f3b06ba99c8904fc2753a5c4aaf6b
MD5 34dac3e98d283aaf2ba73aa5435466a6
BLAKE2b-256 f6c8228fa5edd8c71805dd921bff8a80bfde67aad986f24cd6cd3242f9980f00

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-win_amd64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.34.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c0f9416a6759b45627a6de9cc2767fc2a871e17bf9dcdf0b2880b8d8c1e7f34
MD5 e3ca158fbd6129842e6dbf6a80114452
BLAKE2b-256 ecc45949d072bf56087bf07ef0e47f8a32f18fc67f66ab2a92846870266316ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.34.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 51eaf3f8a15bd6c4a80f493f7ca003ff8dca4e98a231fb809149a304f78b7519
MD5 816e1f8a6d8e1c31630b00fd995b657e
BLAKE2b-256 d9afe79e2ce1ee1f469687644a24306a0e592d42f1299e69244325f40dada80f

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.34.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 241571ad18badb5a7a6e2e25ded2c5ac64a4d5ecd7ac432044fb02b25bacb4cd
MD5 32bd4b12c483dfd3144a30e7f8174d3c
BLAKE2b-256 eb77eb80f3f195bea7817ec8884783dfef6b9218d2527f1a0af15c5d396e8a5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.34.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7fc67731752b8c56329c114c3c30747648f8d97327523c84cec4ccfb5a907215
MD5 d2e08902dca35e3ba28e52c071e7867b
BLAKE2b-256 8a80811fc97e635dbe6578091e86fbe31dd5cd5e55de1141642e815b71446613

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-macosx_10_9_x86_64.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2pa_python-0.34.0-py3-none-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for c2pa_python-0.34.0-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6b8c2277f618c6a222f23317d5a07f1457062eb50aaf5769b07fa732855c52be
MD5 8c173390975dcbf952325dc8cdb8e31a
BLAKE2b-256 4aa58fb158639c2ffddd2359f3b68cc4ecfaaf0f9ace9b08001df7437b6fcba1

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.34.0-py3-none-macosx_10_9_universal2.whl:

Publisher: build.yml on contentauth/c2pa-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page