Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 14 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,133 +1,44 @@
# Python API for C2PA
# C2PA Python library

This project provides a Python API for working with [C2PA](https://c2pa.org/) (Coalition for Content Provenance and Authenticity) manifests. It includes functionality for creating, signing, and verifying C2PA manifests, as well as working with assets and assertions.
The [c2pa-python](https://github.com/contentauth/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
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.

## Project Structure
## Prerequisites

```bash
.
├── .github/ # GitHub configuration files
├── artifacts/ # Platform-specific libraries for building (per subfolder)
│ └── your_target_platform/ # Platform-specific artifacts
├── docs/ # Project documentation
├── examples/ # Example scripts demonstrating usage
├── scripts/ # Utility scripts (eg. artifacts download)
├── src/ # Source code
│ └── c2pa/ # Main package directory
│ └── libs/ # Platform-specific libraries
├── tests/ # Unit tests and benchmarks
├── .gitignore # Git ignore rules
├── Makefile # Build and development commands
├── pyproject.toml # Python project configuration
├── requirements.txt # Python dependencies
├── requirements-dev.txt # Development dependencies
└── setup.py # Package setup script
```
This library requires Python version 3.10+.

## Package installation

The c2pa-python package is published to PyPI. You can install it from there by running:
Install the c2pa-python package from PyPI by running:

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

To use the module in your Python code, import like this:
To use the module in Python code, import it like this:

```python
import c2pa
```

## Examples

### Adding a "Do Not Train" Assertion

The `examples/training.py` script demonstrates how to add a "Do Not Train" assertion to an asset and verify it.

### Signing and Verifying Assets

The `examples/sign.py` script shows how to sign an asset with a C2PA manifest and verify it.

## Development Setup

1. Create and activate a virtual environment with native dependencies:

```bash
# Create virtual environment
python -m venv .venv

# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

# load project dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt

# download library artifacts for the current version you want, eg v0.55.0
python scripts/download_artifacts.py c2pa-v0.55.0
```

2. Install the package in development mode:

```bash
pip install -e .
```

This will:

- Copy the appropriate libraries for your platform from `artifacts/` to `src/c2pa/libs/`
- Install the package in development mode, allowing you to make changes to the Python code without reinstalling

## Building Wheels

To build wheels for all platforms that have libraries in the `artifacts/` directory:

```bash
python setup.py bdist_wheel
```

You can use `twine` to verify the wheels have correct metadata:

```bash
twine check dist/*
```

This will create platform-specific wheels in the `dist/` directory.

## Running Tests

Run the tests:

```bash
make test
```

Alternatively, install pytest (if not already installed):

```bash
pip install pytest
```

And run:

```bash
pytest
```
See the [`examples` directory](https://github.com/contentauth/c2pa-python/tree/main/examples) for some helpful examples:
- `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.

## Contributing

Contributions are welcome! Please fork the repository and submit a pull request.
Contributions are welcome! For more information, see [Contributing to the project](https://github.com/contentauth/c2pa-python/blob/main/docs/project-contributions.md).

## License

This project is licensed under the Apache License 2.0 or the MIT License. See the LICENSE-MIT and LICENSE-APACHE files for details.
This project is licensed under the Apache License 2.0 and the MIT License. See the [LICENSE-MIT](https://github.com/contentauth/c2pa-python/blob/main/LICENSE-MIT) and [LICENSE-APACHE](https://github.com/contentauth/c2pa-python/blob/main/LICENSE-APACHE) files for details.
112 changes: 68 additions & 44 deletions docs/project-contributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,51 @@

The information in this page is primarily for those who wish to contribute to the c2pa-python library project itself, rather than those who simply wish to use it in an application. For general contribution guidelines, see [CONTRIBUTING.md](../CONTRIBUTING.md).

## Development
## Setup

It is best to [set up a virtual environment](https://virtualenv.pypa.io/en/latest/installation.html) for development and testing.
It is best to [set up a virtual environment](https://virtualenv.pypa.io/en/latest/installation.html) for development and testing:

To build from source on Linux, install `curl` and `rustup` then set up Python.
```bash
python -m venv .venv
```

Activate the virtual environment.

First update `apt` then (if needed) install `curl`:
- On Windows:
```bash
.venv\Scripts\activate
```
- On macOS/Linux:
```bash
source .venv/bin/activate
```

Load project dependencies:

```bash
apt update
apt install curl
pip install -r requirements.txt
pip install -r requirements-dev.txt
```

Install Rust:
Download library artifacts for the current version you want, (for example, as shown below for v0.55.0):

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
python scripts/download_artifacts.py c2pa-v0.55.0
```

Install Python, `pip`, and `venv`:
Install the package in development mode:

```bash
apt install python3
apt install pip
apt install python3.11-venv
python3 -m venv .venv
pip install -e .
```

This command:

- Copies the appropriate libraries for your platform from `artifacts/` to `src/c2pa/libs/`
- Installs the package in development mode, so you can make changes to the Python code without reinstalling.

## Building wheels

Build the wheel for your platform (from the root of the repository):

```bash
Expand All @@ -42,49 +58,58 @@ pip install -U pytest
python3 -m build --wheel
```

Note: To peek at the Python code (uniffi generated and non-generated), run `maturin develop` and look in the c2pa folder.
To test local wheels locally, enter this command:

## ManyLinux build
```bash
make test-local-wheel-build
```

Build using [manylinux](https://github.com/pypa/manylinux) by using a Docker image as follows:
To verify the builds, enter this command:

```bash
docker run -it quay.io/pypa/manylinux_2_28_aarch64 bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
export PATH=/opt/python/cp312-cp312/bin:$PATH
pip install maturin
pip install venv
pip install build
pip install -U pytest
make verify-wheel-build
```

cd home
git clone https://github.com/contentauth/c2pa-python.git
cd c2pa-python
python3 -m build --wheel
auditwheel repair target/wheels/c2pa_python-0.4.0-py3-none-linux_aarch64.whl
## Project structure

```bash
.
├── .github/ # GitHub configuration files
├── artifacts/ # Platform-specific libraries for building (per subfolder)
│ └── your_target_platform/ # Platform-specific artifacts
├── docs/ # Project documentation
├── examples/ # Example scripts demonstrating usage
├── scripts/ # Utility scripts (eg. artifacts download)
├── src/ # Source code
│ └── c2pa/ # Main package directory
│ └── libs/ # Platform-specific libraries
├── tests/ # Unit tests and benchmarks
├── .gitignore # Git ignore rules
├── Makefile # Build and development commands
├── pyproject.toml # Python project configuration
├── requirements.txt # Python dependencies
├── requirements-dev.txt # Development dependencies
└── setup.py # Package setup script
```

## Testing

We use [PyTest](https://docs.pytest.org/) and [unittest](https://docs.python.org/3/library/unittest.html) for testing.
The project uses [PyTest](https://docs.pytest.org/) and [unittest](https://docs.python.org/3/library/unittest.html) for testing.
Comment thread
crandmck marked this conversation as resolved.

Run tests by following these steps:

1. Activate the virtual environment: `source .venv/bin/activate`
2. (optional) Install dependencies: `pip install -r requirements.txt`
3. Setup the virtual environment with local changes: `maturin develop`
4. Run the tests: `pytest`
5. Deactivate the virtual environment: `deactivate`

For example:

```bash
source .venv/bin/activate
maturin develop
python3 tests/training.py
deactivate
```
4. Run the tests:
```bash
make test
```
5. Alternatively, install `pytest` (if not already installed) and run it:
```bash
pip install pytest
pytest
```
**Warning**: Using `pytest` can lead to issues if you often switch between virtual environments.

### Testing during bindings development

Comment thread
crandmck marked this conversation as resolved.
Expand All @@ -102,4 +127,3 @@ To rebuild and test, enter these commands:
make build-python
make test
```

Loading