|
1 | | -# C2PA Python library |
| 1 | +# Python API for C2PA |
2 | 2 |
|
3 | | -The [c2pa-python](https://github.com/contentauth/c2pa-python) repository implements Python bindings for the Content Authenticity Initiative (CAI) SDK. |
4 | | -It enables you to read and validate C2PA manifest data from and add signed manifests to media files in supported formats. |
| 3 | +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. |
5 | 4 |
|
6 | | -**NOTE**: Starting with version 0.5.0, this package has a completely different API from version 0.4.0. See [Release notes](docs/release-notes.md) for more information. |
| 5 | +## Features |
7 | 6 |
|
8 | | -**WARNING**: This is an prerelease version of this library. There may be bugs and unimplemented features, and the API is subject to change. |
| 7 | +- Create and sign C2PA manifests using various signing algorithms. |
| 8 | +- Verify C2PA manifests and extract metadata. |
| 9 | +- Add assertions and ingredients to assets. |
| 10 | +- Examples and unit tests to demonstrate usage. |
9 | 11 |
|
10 | | -<div style={{display: 'none'}}> |
| 12 | +## Project Structure |
11 | 13 |
|
12 | | -Additional documentation: |
13 | | -- [Using the Python library](docs/usage.md) |
14 | | -- [Release notes](docs/release-notes.md) |
15 | | -- [Contributing to the project](docs/project-contributions.md) |
| 14 | +```bash |
| 15 | +python_api/ |
| 16 | + ├── examples/ # Example scripts demonstrating usage |
| 17 | + ├── src/ # Source code for the C2PA Python API |
| 18 | + │ └── c2pa/ # Main package directory |
| 19 | + │ └── libs/ # Platform-specific libraries |
| 20 | + ├── tests/ # Unit tests and benchmarks |
| 21 | + ├── artifacts/ # Platform-specific libraries for building |
| 22 | + │ ├── win_amd64/ # Windows x64 libraries |
| 23 | + │ ├── win_arm64/ # Windows ARM64 libraries |
| 24 | + │ ├── macosx_x86_64/ # macOS x64 libraries |
| 25 | + │ ├── macosx_arm64/ # macOS ARM64 libraries |
| 26 | + │ ├── linux_x86_64/ # Linux x64 libraries |
| 27 | + │ └── linux_aarch64/ # Linux ARM64 libraries |
| 28 | + ├── requirements.txt # Python dependencies |
| 29 | + └── README.md # Project documentation |
| 30 | +``` |
| 31 | + |
| 32 | +## Development Setup |
16 | 33 |
|
17 | | -</div> |
| 34 | +1. Create and activate a virtual environment: |
| 35 | +```bash |
| 36 | +# Create virtual environment |
| 37 | +python -m venv .venv |
| 38 | + |
| 39 | +# Activate virtual environment |
| 40 | +# On Windows: |
| 41 | +.venv\Scripts\activate |
| 42 | +# On macOS/Linux: |
| 43 | +source .venv/bin/activate |
18 | 44 |
|
19 | | -## Installation |
| 45 | +# load project dependencies |
| 46 | +pip install -r requirements.txt |
20 | 47 |
|
21 | | -Install from PyPI by entering this command: |
| 48 | +# download library artifacts for the current version you want |
| 49 | +python scripts/download_artifacts.py c2pa-v0.49.5 |
| 50 | +``` |
22 | 51 |
|
| 52 | + |
| 53 | +2. Install the package in development mode: |
23 | 54 | ```bash |
24 | | -pip install -U c2pa-python |
| 55 | +pip install -e . |
25 | 56 | ``` |
26 | 57 |
|
27 | | -This is a platform wheel built with Rust that works on Windows, macOS, and most Linux distributions (using [manylinux](https://github.com/pypa/manylinux)). If you need to run on another platform, see [Project contributions - Development](docs/project-contributions.md#development) for information on how to build from source. |
| 58 | +This will: |
| 59 | +- Copy the appropriate libraries for your platform from `artifacts/` to `src/c2pa/libs/` |
| 60 | +- Install the package in development mode, allowing you to make changes to the Python code without reinstalling |
28 | 61 |
|
29 | | -### Updating |
| 62 | +## Building Wheels |
30 | 63 |
|
31 | | -Determine what version you've got by entering this command: |
| 64 | +To build wheels for all platforms that have libraries in the `artifacts/` directory: |
32 | 65 |
|
33 | 66 | ```bash |
34 | | -pip list | grep c2pa-python |
| 67 | +python setup.py bdist_wheel |
35 | 68 | ``` |
36 | 69 |
|
37 | | -If the version shown is lower than the most recent version, then update by [reinstalling](#installation). |
| 70 | +This will create platform-specific wheels in the `dist/` directory. |
38 | 71 |
|
39 | | -### Reinstalling |
| 72 | +## Running Tests |
40 | 73 |
|
41 | | -If you tried unsuccessfully to install this package before the [0.40 release](https://github.com/contentauth/c2pa-python/releases/tag/v0.4), then use this command to reinstall: |
| 74 | +Install pytest (if not already installed): |
| 75 | +```bash |
| 76 | +pip install pytest |
| 77 | +``` |
42 | 78 |
|
| 79 | +Run the tests: |
43 | 80 | ```bash |
44 | | -pip install --upgrade --force-reinstall c2pa-python |
| 81 | +pytest |
45 | 82 | ``` |
46 | 83 |
|
47 | | -## Supported formats |
| 84 | +## Examples |
48 | 85 |
|
49 | | -The Python library [supports the same media file formats](https://github.com/contentauth/c2pa-rs/blob/main/docs/supported-formats.md) as the Rust library. |
| 86 | +### Adding a "Do Not Train" Assertion |
| 87 | +The `examples/training.py` script demonstrates how to add a "Do Not Train" assertion to an asset and verify it. |
50 | 88 |
|
51 | | -## License |
| 89 | +### Signing and Verifying Assets |
| 90 | +The `examples/test.py` script shows how to sign an asset with a C2PA manifest and verify it. |
52 | 91 |
|
53 | | -This package is distributed under the terms of both the [MIT license](https://github.com/contentauth/c2pa-python/blob/main/LICENSE-MIT) and the [Apache License (Version 2.0)](https://github.com/contentauth/c2pa-python/blob/main/LICENSE-APACHE). |
| 92 | +## Contributing |
54 | 93 |
|
55 | | -Note that some components and dependent crates are licensed under different terms; please check the license terms for each crate and component for details. |
| 94 | +Contributions are welcome! Please fork the repository and submit a pull request. |
56 | 95 |
|
57 | | -### Contributions and feedback |
| 96 | +## License |
58 | 97 |
|
59 | | -We welcome contributions to this project. For information on contributing, providing feedback, and about ongoing work, see [Contributing](https://github.com/contentauth/c2pa-python/blob/main/CONTRIBUTING.md). |
| 98 | +This project is licensed under the Apache License 2.0 or the MIT License. See the LICENSE-MIT and LICENSE-APACHE files for details. |
0 commit comments