Skip to content
Draft
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ See the [`examples` directory](https://github.com/contentauth/c2pa-python/tree/m

## API reference documentation

See [the section in Contributing to the project](https://github.com/contentauth/c2pa-python/blob/main/docs/project-contributions.md#api-reference-documentation).
Documentation is published at [github.io/c2pa-python/api/c2pa](https://contentauth.github.io/c2pa-python/api/c2pa/index.html).

To build documentation locally, refer to [this section in Contributing to the project](https://github.com/contentauth/c2pa-python/blob/main/docs/project-contributions.md#api-reference-documentation).

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion c2pa-native-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c2pa-v0.67.1
c2pa-v0.74.0
8 changes: 6 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python example code
# Python example code

The `examples` directory contains some small examples of using the Python library.
The `examples` directory contains some small examples of using this Python library.
The examples use asset files from the `tests/fixtures` directory, save the resulting signed assets to the temporary `output` directory, and display manifest store data and other output to the console.

## Signing and verifying assets
Expand Down Expand Up @@ -96,3 +96,7 @@ In this example, `SignerInfo` creates a `Signer` object that signs the manifest.
```bash
python examples/sign_info.py
```

## Backend application example

[c2pa-python-example](https://github.com/contentauth/c2pa-python-example) is an example of a simple application that accepts an uploaded JPEG image file, attaches a C2PA manifest, and signs it using a certificate. The app uses the CAI Python library and the Flask Python framework to implement a back-end REST endpoint; it does not have an HTML front-end, so you have to use something like curl to access it. This example is a development setup and should not be deployed as-is to a production environment.
10 changes: 6 additions & 4 deletions examples/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
fixtures_dir = os.path.join(os.path.dirname(__file__), "../tests/fixtures/")
output_dir = os.path.join(os.path.dirname(__file__), "../output/")

# Ensure the output directory exists
# Ensure the output directory exists.
if not os.path.exists(output_dir):
os.makedirs(output_dir)

Expand All @@ -43,7 +43,7 @@
with open(fixtures_dir + "es256_private.key", "rb") as key_file:
key = key_file.read()

# Define a callback signer function
# Define a callback signer function.
def callback_signer_es256(data: bytes) -> bytes:
"""Callback function that signs data using ES256 algorithm."""
private_key = serialization.load_pem_private_key(
Expand All @@ -60,7 +60,6 @@ def callback_signer_es256(data: bytes) -> bytes:
# Create a manifest definition as a dictionary.
# This manifest follows the V2 manifest format.
manifest_definition = {
"claim_generator": "python_example",
"claim_generator_info": [{
"name": "python_example",
"version": "0.0.1",
Expand All @@ -87,7 +86,7 @@ def callback_signer_es256(data: bytes) -> bytes:
}

# Sign the image with the signer created above,
# which will use the callback signer
# which will use the callback signer.
print("\nSigning the image file...")

with c2pa.Signer.from_callback(
Expand All @@ -107,6 +106,9 @@ def callback_signer_es256(data: bytes) -> bytes:
print("\nReading signed image metadata:")
with open(output_dir + "A_signed.jpg", "rb") as file:
with c2pa.Reader("image/jpeg", file) as reader:
# The validation state will depend on loaded trust settings.
# Without loaded trust settings,
# the manifest validation_state will be "Invalid".
print(reader.json())

print("\nExample completed successfully!")
Expand Down
3 changes: 3 additions & 0 deletions examples/sign_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
print("\nReading signed image metadata:")
with open(output_dir + "C_signed.jpg", "rb") as file:
with c2pa.Reader("image/jpeg", file) as reader:
# The validation state will depend on loaded trust settings.
# Without loaded trust settings,
# the manifest validation_state will be "Invalid".
print(reader.json())

print("\nExample completed successfully!")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "c2pa-python"
version = "0.27.1"
version = "0.28.0"
requires-python = ">=3.10"
description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library"
readme = { file = "README.md", content-type = "text/markdown" }
Expand Down
4 changes: 4 additions & 0 deletions src/c2pa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
C2paError,
Reader,
C2paSigningAlg,
C2paDigitalSourceType,
C2paBuilderIntent,
C2paSignerInfo,
Signer,
Stream,
Expand All @@ -35,6 +37,8 @@
'C2paError',
'Reader',
'C2paSigningAlg',
'C2paDigitalSourceType',
'C2paBuilderIntent',
'C2paSignerInfo',
'Signer',
'Stream',
Expand Down
Loading
Loading