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

Uploaded Python 3Windows x86-64

c2pa_python-0.32.14-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.14-py3-none-manylinux_2_28_aarch64.whl (14.9 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

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

Uploaded Python 3macOS 11.0+ ARM64

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

Uploaded Python 3macOS 10.9+ x86-64

c2pa_python-0.32.14-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.14.tar.gz.

File metadata

  • Download URL: c2pa_python-0.32.14.tar.gz
  • Upload date:
  • Size: 85.9 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.14.tar.gz
Algorithm Hash digest
SHA256 68b90e4cca21fedd91608235f99fcf22bb31129caf642bb7136721c02c3f6085
MD5 795ea4d93e72caa7a7f5569a32a83be4
BLAKE2b-256 020eac18d2814db363a4ae722e39cf1ec72b2da5904bf1d56a7b62c0799ee074

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c8605e8de6b7a01d666a73468f3c6bef0727b34920f2b5cfcb73f7213568b89f
MD5 7635259be325282a82b63e1b33f3cf94
BLAKE2b-256 52d687790e250bb131bdcf0c0d2c9074a59268de8f21225982bfbdae776a8da9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6cecedb3d5538bc9d0863f193d67c64a67936ab3228404cf60d50f8c14b52486
MD5 ca0ffcd2732031821b877a8f3f064c2b
BLAKE2b-256 7acdbf0859706900268307dd190bc9fa910ce93c55c1188512469ac880d194e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eae423e0e7ebcd3e25449dfd7966a92b22a93f93aea24cc39076ee30cf90f418
MD5 ed754df399949e51b357582f1ffed6da
BLAKE2b-256 c4ee112e1baf5fa3a56211d3e75bc6957ceb4b5d983cc6b79e567b13da9514f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 edd748b00b60740e0726c169d58e8babae9c5c0e06838ade761fbb46c0a233a8
MD5 c159c3f6d7644f5271a4e4a1f8de08aa
BLAKE2b-256 e5cd78cf20da5d9aea01da73d38c8de53e7ee391483d09d2bbde8ab1b96f2a72

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9bce9af3ea8f0ff188a0b64d4eb10536fac04350efadd25af32fdacc9425024f
MD5 5955037650cf066c0aa05326aeb41a8f
BLAKE2b-256 6ac7d792dfb7faf6c60b723c5955c9d23425e7fc00bebc7d15c996ca68fd4681

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for c2pa_python-0.32.14-py3-none-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4bf089f2ad710e12aec01835e37dbee98dc2f47d0db1baaedcfbfc1700ca8340
MD5 ff71f472e5b4dfa18900829cb3d62850
BLAKE2b-256 9c8aad3f56028a9634f89d84de124f51b6360ce3a9eea7bf869f0d2cae1bc475

See more details on using hashes here.

Provenance

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