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.37.0.tar.gz (87.4 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.37.0-py3-none-win_arm64.whl (84.9 MB view details)

Uploaded Python 3Windows ARM64

c2pa_python-0.37.0-py3-none-win_amd64.whl (87.5 MB view details)

Uploaded Python 3Windows x86-64

c2pa_python-0.37.0-py3-none-manylinux_2_28_x86_64.whl (14.7 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

c2pa_python-0.37.0-py3-none-manylinux_2_28_aarch64.whl (14.0 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

c2pa_python-0.37.0-py3-none-macosx_11_0_arm64.whl (13.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

c2pa_python-0.37.0-py3-none-macosx_10_9_x86_64.whl (14.1 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

c2pa_python-0.37.0-py3-none-macosx_10_9_universal2.whl (16.2 MB view details)

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

File details

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

File metadata

  • Download URL: c2pa_python-0.37.0.tar.gz
  • Upload date:
  • Size: 87.4 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.37.0.tar.gz
Algorithm Hash digest
SHA256 933c220447ff366c93aaa44ceb09f1b280da4f5103de436a63686abe2ef7516c
MD5 dd4b1564a9e37f929a16d1b5fe02ebbb
BLAKE2b-256 e9ea789ffb0d839fddc73c511a96e37d7a203190ebe9a55b509bc1a7dd2e65a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2pa_python-0.37.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.37.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: c2pa_python-0.37.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 84.9 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.37.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 5bd03794a73b933c65020b3bbfbd6f226a7cb881a78a32cf9125860136bbef78
MD5 0055cd8d43888fbdc242789494c96b37
BLAKE2b-256 181c923b42e3c24f8b5ff19af5c33bae6190e6cd7f543ad6232b26e643a19fd6

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: c2pa_python-0.37.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 87.5 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.37.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e760bd91568e6780da262a75a844ccd3aee1534bc09e88a459cab8c5e586984d
MD5 4fedd806289dee748e821ecdd58e95d4
BLAKE2b-256 ec019d5f2002eaed3ed4fd099edcdec9a3c7c945a6a6323c9ff2226650bda234

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.37.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fce1c8086c26a138053af0da7970e1240a8f718ccb61dccaba9595f08973ab3c
MD5 45e1587fc384d4137fa3028f89a1b77a
BLAKE2b-256 325240f757764952489615121d5a25ca0d6f4b173eba0ccb1236c075ae770ec8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.37.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a43c3d77b057079f780e420751ee933cdb882575ffcc74e437c1127f84d52f79
MD5 6f86e3f6b96d76f1e82bd1e398e4f9c8
BLAKE2b-256 48d466de1a7cd95bc45ebf07a26d8c7349cfa9898025bc35cbf6abe744f50801

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.37.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ed34ae29f914ddcb84b9457fb71c7fb9c5cc7f906455241b987cf7637d164d2
MD5 ac04db2fb56225bc97778b02d65a24da
BLAKE2b-256 752faf42d30f1fc72e61011f48bce84fc261ed2656cadcbd239488c484bb0581

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.37.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 b77bab9746adf4f760098061ad9a322fd7430ee024bfab19c6ac5283dd387da7
MD5 62a0d6b8c51bb3847837f78f85ee112f
BLAKE2b-256 356759a25d85a2889eb3d433e505ab4ece6c47fa895473a54eb74c60a376c0ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.37.0-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c3100abba0d18d56cfa752fffd81f05af5a23b4ca0f1ec443926d92c6cfac4b
MD5 2749614f47ac74af3fde07b60b9bb1e7
BLAKE2b-256 124a3c7bf0391f42620f726543a6324cf83dadf29168f2e6117df7fd910da430

See more details on using hashes here.

Provenance

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