Skip to main content

Fast Python library for reading C2PA metadata using PyO3 bindings to c2pa-rs

Project description

fast-c2pa-python

A Python library for reading C2PA metadata based on c2pa-rs

Overview

This library provides fast C2PA metadata extraction from digital assets using direct PyO3 bindings to the Rust C2PA implementation. It was created to address performance bottlenecks in existing Python C2PA libraries.

Note: This library is designed for reading C2PA metadata only. It does not support writing or creating C2PA metadata at this time.

Benchmarks

Implementation Average Read Time
c2pa-python (UniFFI) v8 ~486ms
numbers-c2pa ~17ms
fast-c2pa-python (PyO3) ~8ms
Native Rust ~7ms

Installation

pip install fast-c2pa-python

Usage

Basic Usage

from fast_c2pa_python import read_c2pa_from_file

# Read C2PA metadata from a file (with automatic MIME type detection)
metadata = read_c2pa_from_file("path/to/image.jpg")
print(metadata)

# You can also specify the MIME type explicitly if needed
metadata = read_c2pa_from_file("path/to/image.jpg", "image/jpeg")

Reading from Binary Data

from fast_c2pa_python import read_c2pa_from_bytes

# From HTTP response or other binary source
response = requests.get("https://example.com/image.jpg")
metadata = read_c2pa_from_bytes(response.content, "image/jpeg")

# Or from a file opened in binary mode
with open("path/to/image.jpg", "rb") as f:
    data = f.read()
    metadata = read_c2pa_from_bytes(data, "image/jpeg")

Example Output

{
    "title": "Image Title",
    "generator": "Adobe Photoshop",
    "thumbnail": {...},
    "assertions": [...],
    "signature_info": {
        "issuer": "Example Issuer",
        "time": "2023-05-23T10:30:15Z",
        "cert_serial_number": "1234567890"
    },
    "ingredients": [...],
    # Additional manifest data
}

Testing

The library includes API compatibility tests to ensure functionality.

Running Tests

Install test dependencies:

pip install -r tests/requirements.txt

Run API tests:

python run_tests.py --api-only

Development

This library is built using Maturin, which provides Python bindings for Rust with PyO3.

Setting Up Development Environment

# Install Maturin
pip install maturin

# Development build (debug mode)
maturin develop

# Run in release mode for better performance
maturin develop --release

Building Wheel Files

# Build wheel for the current platform
maturin build --release

Wheel files are generated in the `target/wheels/` directory and can be shared directly with users who can install them using pip:

```bash
pip install /path/to/fast_c2pa_python-x.x.x-cp3xx-cp3xx-platform.whl

License

This project is dual-licensed under both MIT and Apache 2.0 licenses to ensure compatibility with the underlying c2pa-rs library.

Attribution

This library is built upon the excellent work of the c2pa-rs library by the Content Authenticity Initiative. The c2pa-rs library provides the core C2PA implementation in Rust, and this project creates Python bindings using PyO3 for improved performance.

Developed by: Sightengine - AI-powered content moderation

Key Dependencies:

  • c2pa-rs - Core C2PA implementation
  • PyO3 - Rust bindings for Python

Special thanks to the Content Authenticity Initiative and the c2pa-rs contributors for their foundational work on C2PA standards and implementation.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

fast_c2pa_python-0.1.6-cp312-cp312-manylinux_2_34_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fast_c2pa_python-0.1.6-cp311-cp311-manylinux_2_34_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

File details

Details for the file fast_c2pa_python-0.1.6-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fast_c2pa_python-0.1.6-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c3712ccff62fd1a7c2930ad2b1de0d16a6cd78b712dee38e4da5e87291daeb0e
MD5 c4bf763e68dd43d83e2a4d8c95e6b071
BLAKE2b-256 7565d6cea3bbdbd8050e291b4efbee860cb453f7a98f0e2f953a94436190c4fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_c2pa_python-0.1.6-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: cross_platform_tests.yml on Sightengine/fast_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 fast_c2pa_python-0.1.6-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fast_c2pa_python-0.1.6-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bc74e4d84c8771a3b876bc16994b8d0dd92e69011d5b4fdac01ee7d45eb9ece0
MD5 ad0dbf81b0e7f7a975f5872213b6c283
BLAKE2b-256 251c06c00274de7506cb9fb8e4170293ec60e2be94828c226b6418342017413c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_c2pa_python-0.1.6-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: cross_platform_tests.yml on Sightengine/fast_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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page