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.
It is best to set up a virtual environment for development and testing:
python -m venv .venvActivate the 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.txtDownload c2pa-rs library artifacts for the current version you want, (for example, as shown below for v0.73.1):
python scripts/download_artifacts.py c2pa-v0.73.1Install the package in development mode:
pip install -e .This command:
- Copies the appropriate libraries for your platform from
artifacts/tosrc/c2pa/libs/ - Installs the package in development mode, so you can make changes to the Python code without reinstalling.
Build the wheel for your platform (from the root of the repository):
source .venv/bin/activate
pip install -r requirements.txt
python3 -m pip install build
pip install -U pytest
python3 -m build --wheelTo test local wheels locally, enter this command:
make test-local-wheel-buildTo verify the builds, enter this command:
make verify-wheel-build.
├── .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 scriptThe project uses PyTest and unittest for testing.
Run tests by following these steps:
- Activate the virtual environment:
source .venv/bin/activate - (optional) Install dependencies:
pip install -r requirements.txt - Run the tests:
make test - Alternatively, install
pytest(if not already installed) and run it:Warning: Usingpip install pytest pytest
pytestcan lead to issues if you often switch between virtual environments.
While developing bindings locally, we use unittest, since PyTest can get confused by virtual environment re-deployments (especially if you bump the version number).
To run tests while developing bindings, enter this command:
make testTo rebuild and test, enter these commands:
make build-python
make testWe use Sphinx autodoc to generate API docs.
Install development dependencies:
cd c2pa-python
python3 -m pip install -r requirements-dev.txt
Build docs by entering make -C docs or:
python3 scripts/generate_api_docs.py
View the output by loading api-docs/build/html/index.html in a web browser.
This uses sphinx-autoapi to parse src/c2pa directly, avoiding imports of native libs.
- Entry script:
scripts/generate_api_docs.py - Config:
api-docs/conf.py; index:api-docs/index.rst
Sphinx config is in api-docs/conf.py, which uses index.rst.