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.32.13.tar.gz (85.7 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.32.13-py3-none-win_amd64.whl (89.9 MB view details)

Uploaded Python 3Windows x86-64

c2pa_python-0.32.13-py3-none-manylinux_2_28_x86_64.whl (15.6 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

c2pa_python-0.32.13-py3-none-manylinux_2_28_aarch64.whl (14.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

c2pa_python-0.32.13-py3-none-macosx_11_0_arm64.whl (14.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

c2pa_python-0.32.13-py3-none-macosx_10_9_x86_64.whl (15.1 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

c2pa_python-0.32.13-py3-none-macosx_10_9_universal2.whl (16.6 MB view details)

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

File details

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

File metadata

  • Download URL: c2pa_python-0.32.13.tar.gz
  • Upload date:
  • Size: 85.7 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.32.13.tar.gz
Algorithm Hash digest
SHA256 8330aa64278e0ad392f8851f3b7aa6be4aaa9dabc31b6398d1927ff9d857cc8d
MD5 dae2832e094ee9039fc20dcad9c7a56b
BLAKE2b-256 5f5eb388881451912fb693cbdac7b8d3dbfbf39e747303a619ad7576a912ed7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13.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.32.13-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 307e0388f20cfdaa826606f09e9ee755b22f4a03c65e4365834766717031018e
MD5 98303b296c12f004488b50d3d71b78d8
BLAKE2b-256 17bdcfc0c50350ff40ef4cb3d6365932c558d95d9b8f8c73dd8d22d4cb289ef0

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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.32.13-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2dfbc3aa1b71ac9ae55cd4407453f9f60e04dc01b8686061d70ccc50a822c0ae
MD5 b546977a2c99cf741f72cdd5b0374e47
BLAKE2b-256 e3aeb40693dfd6921b37c3c67ebac476cf9268c9f232b3143d076ad12ddbb8c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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.32.13-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 96c464209c1f452c34d21bb6cfbbb8337c301a50b5482dbc894022263fcfbf66
MD5 b2c82d36e26d8e691b9bbbcc2ba034d6
BLAKE2b-256 c0ca54382a478bada9b7d2b38e458c75f921bda3828a2b16854cc96ad1a267e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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.32.13-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38c8501162c7a2ecc3fe0f8df0b08b67281aecd0099c11bed93b3562e81f5bcf
MD5 3db39f691a19f5fe7c5458080bdae641
BLAKE2b-256 7ebb98c1a6cc184b48004ee09ba2ac8214c0ae0aea0e1cfbe2cd89d24fd709cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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.32.13-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3c30debb2ccbac7260e896f92924248498c09044cad2654a574f500916b80752
MD5 1b18118bf663ed974bbdd8e1c388c4fe
BLAKE2b-256 02bdd588e8b9fda15e926e0ccf792a9e8a95cadbd96826be6ef744c4a9f8cea2

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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.32.13-py3-none-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for c2pa_python-0.32.13-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7d15e78aed6ed38ae2b95463cf48715dc16f3c725dff3a66b42b6a3ea207eb1d
MD5 9d6a4efd862c9ecf113a06fea20f4220
BLAKE2b-256 c8ef988be50491cda8f9b5b07c2d7fbbfacc7bf31155911e65bbb0d85d459bb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.32.13-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