Metadata-Version: 2.4
Name: fast-c2pa-python
Version: 0.1.4
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX :: Linux
License-File: LICENSE
Summary: Fast Python library for reading C2PA metadata using PyO3 bindings to c2pa-rs
Keywords: c2pa,metadata,python,bindings
Author: Sightengine <info@sightengine.com>
Author-email: Sightengine <info@sightengine.com>
License: MIT OR Apache-2.0
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# 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

```bash
pip install fast-c2pa-python
```

## Usage

### Basic Usage

```python
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

```python
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

```python
{
    "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:

```bash
pip install -r tests/requirements.txt
```

Run API tests:

```bash
python run_tests.py --api-only
```

## Development

This library is built using [Maturin](https://github.com/PyO3/maturin), which provides Python bindings for Rust with [PyO3](https://github.com/PyO3/pyo3).

### Setting Up Development Environment

```bash
# Install Maturin
pip install maturin

# Development build (debug mode)
maturin develop

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

### Building Wheel Files

```bash
# 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](https://github.com/contentauth/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](https://sightengine.com) - AI-powered content moderation

**Key Dependencies:**
- [c2pa-rs](https://github.com/contentauth/c2pa-rs) - Core C2PA implementation
- [PyO3](https://github.com/PyO3/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.
