markproof 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {markproof-0.2.0 → markproof-0.3.0}/PKG-INFO +2 -2
- {markproof-0.2.0 → markproof-0.3.0}/README.md +69 -69
- {markproof-0.2.0 → markproof-0.3.0}/markproof/client.py +20 -8
- {markproof-0.2.0 → markproof-0.3.0}/markproof.egg-info/PKG-INFO +2 -2
- {markproof-0.2.0 → markproof-0.3.0}/pyproject.toml +1 -1
- {markproof-0.2.0 → markproof-0.3.0}/tests/test_client.py +278 -249
- {markproof-0.2.0 → markproof-0.3.0}/LICENSE +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof/__init__.py +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof/batches.py +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof/errors.py +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof/webhooks.py +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof.egg-info/SOURCES.txt +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof.egg-info/dependency_links.txt +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof.egg-info/requires.txt +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/markproof.egg-info/top_level.txt +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/setup.cfg +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/tests/test_batches.py +0 -0
- {markproof-0.2.0 → markproof-0.3.0}/tests/test_webhooks.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: markproof
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python client for the Markproof API - EU AI Act Article 50 watermarking and verification.
|
|
5
5
|
Author-email: Markproof <support@markproof.co>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -49,7 +49,7 @@ print(result.summary)
|
|
|
49
49
|
|
|
50
50
|
- `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
|
|
51
51
|
- `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file", visible_label=None, label_position=None)` → `MarkResult` — `file` is a path (`str`/`os.PathLike`) or raw `bytes` (in which case `filename` is required). `response_format="file"` (default) returns the marked bytes inline (`result.file`/`result.content_type`); `"url"` returns a short-lived signed download URL instead (`result.file_url`, ~1 hour — download promptly rather than caching it). Either way you also get `asset_id`, `watermark_code`, `verify_url`, `c2pa_manifest_label`. `visible_label` (images only): `True` draws a visible "AI-generated" label (EU AI Act Art. 50(4)) before marking, or pass your own text (max 40 characters); `label_position` picks the corner (`"bottom-right"` default, `"bottom-left"`, `"top-right"`, `"top-left"`).
|
|
52
|
-
- `client.verify(file, filename=None)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`.
|
|
52
|
+
- `client.verify(file, filename=None)` or `client.verify(url=...)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`. Direct uploads are limited to about 4.5 MB; pass a public `url` (up to 25 MB) for bigger files, such as marked audio, which comes back as WAV (e.g. a batch item's `file_url`).
|
|
53
53
|
- `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
|
|
54
54
|
|
|
55
55
|
All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
# markproof
|
|
2
|
-
|
|
3
|
-
Python client for the [Markproof](https://markproof.co) API — EU AI Act Article 50 watermarking and verification in one call. Thin wrapper over `requests`.
|
|
4
|
-
|
|
5
|
-
> **Is your AI output Article 50-ready?** Drop a file into the [free checker](https://markproof.co/check) (no signup) to see whether it carries a watermark and signed Content Credentials.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
pip install markproof
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```python
|
|
16
|
-
from markproof import Markproof
|
|
17
|
-
|
|
18
|
-
client = Markproof(api_key="lt_live_...")
|
|
19
|
-
|
|
20
|
-
marked = client.mark("generated.png", generator_name="my-app", model_name="my-model-v1")
|
|
21
|
-
print(marked.watermark_code, marked.verify_url)
|
|
22
|
-
with open("generated-marked.png", "wb") as f:
|
|
23
|
-
f.write(marked.file)
|
|
24
|
-
|
|
25
|
-
result = client.verify("generated-marked.png")
|
|
26
|
-
print(result.summary)
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## API
|
|
30
|
-
|
|
31
|
-
- `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
|
|
32
|
-
- `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file", visible_label=None, label_position=None)` → `MarkResult` — `file` is a path (`str`/`os.PathLike`) or raw `bytes` (in which case `filename` is required). `response_format="file"` (default) returns the marked bytes inline (`result.file`/`result.content_type`); `"url"` returns a short-lived signed download URL instead (`result.file_url`, ~1 hour — download promptly rather than caching it). Either way you also get `asset_id`, `watermark_code`, `verify_url`, `c2pa_manifest_label`. `visible_label` (images only): `True` draws a visible "AI-generated" label (EU AI Act Art. 50(4)) before marking, or pass your own text (max 40 characters); `label_position` picks the corner (`"bottom-right"` default, `"bottom-left"`, `"top-right"`, `"top-left"`).
|
|
33
|
-
- `client.verify(file, filename=None)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`.
|
|
34
|
-
- `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
|
|
35
|
-
|
|
36
|
-
All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
|
|
37
|
-
|
|
38
|
-
## Batches and webhooks
|
|
39
|
-
|
|
40
|
-
For volume, queue many files at once instead of calling `mark` per file. Each item counts as one mark.
|
|
41
|
-
|
|
42
|
-
```python
|
|
43
|
-
created = client.create_batch(
|
|
44
|
-
urls=["https://cdn.example.com/1.png", "https://cdn.example.com/2.png"], # and/or files=["a.png", (data, "b.wav")]
|
|
45
|
-
generator_name="your-app",
|
|
46
|
-
webhook_url="https://your-app.example.com/hooks/markproof", # optional
|
|
47
|
-
)
|
|
48
|
-
batch = client.wait_for_batch(created.batch_id) # or get_batch(...), or wait for the webhook
|
|
49
|
-
for item in batch.items:
|
|
50
|
-
print(item.index, item.status, item.file_url or item.error)
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
- `client.create_batch(files=None, urls=None, generator_name=None, model_name=None, webhook_url=None)` → `CreatedBatch` — files go up in one multipart request (keep the total under ~4.5 MB; use `urls` for more). Max items per batch: 10 Free, 100 Indie, 1,000 Pro.
|
|
54
|
-
- `client.get_batch(batch_id)` → `Batch` — `status` (`queued`/`processing`/`completed`/`partial`/`failed`), `counts`, and `items` with `asset_id`, `watermark_code`, `verify_url`, `file_url` (signed, ~1 hour; call again for a fresh one) or `error`.
|
|
55
|
-
- `client.wait_for_batch(batch_id, interval=3.0, timeout=900, on_progress=None)` — polls until the batch is final.
|
|
56
|
-
|
|
57
|
-
Verify webhooks with the raw request body and your signing secret from the dashboard:
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
from markproof import verify_webhook_signature
|
|
61
|
-
|
|
62
|
-
ok = verify_webhook_signature(
|
|
63
|
-
request.get_data(), # the exact bytes received, not re-serialized JSON
|
|
64
|
-
request.headers.get("Markproof-Signature"),
|
|
65
|
-
os.environ["MARKPROOF_WEBHOOK_SECRET"],
|
|
66
|
-
)
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
`parse_webhook_event(...)` does the same and returns the `batch.completed` event, raising `WebhookSignatureError` if the signature doesn't match. Event `id`s are stable across retries, so use them to drop duplicates.
|
|
1
|
+
# markproof
|
|
2
|
+
|
|
3
|
+
Python client for the [Markproof](https://markproof.co) API — EU AI Act Article 50 watermarking and verification in one call. Thin wrapper over `requests`.
|
|
4
|
+
|
|
5
|
+
> **Is your AI output Article 50-ready?** Drop a file into the [free checker](https://markproof.co/check) (no signup) to see whether it carries a watermark and signed Content Credentials.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install markproof
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from markproof import Markproof
|
|
17
|
+
|
|
18
|
+
client = Markproof(api_key="lt_live_...")
|
|
19
|
+
|
|
20
|
+
marked = client.mark("generated.png", generator_name="my-app", model_name="my-model-v1")
|
|
21
|
+
print(marked.watermark_code, marked.verify_url)
|
|
22
|
+
with open("generated-marked.png", "wb") as f:
|
|
23
|
+
f.write(marked.file)
|
|
24
|
+
|
|
25
|
+
result = client.verify("generated-marked.png")
|
|
26
|
+
print(result.summary)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
- `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
|
|
32
|
+
- `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file", visible_label=None, label_position=None)` → `MarkResult` — `file` is a path (`str`/`os.PathLike`) or raw `bytes` (in which case `filename` is required). `response_format="file"` (default) returns the marked bytes inline (`result.file`/`result.content_type`); `"url"` returns a short-lived signed download URL instead (`result.file_url`, ~1 hour — download promptly rather than caching it). Either way you also get `asset_id`, `watermark_code`, `verify_url`, `c2pa_manifest_label`. `visible_label` (images only): `True` draws a visible "AI-generated" label (EU AI Act Art. 50(4)) before marking, or pass your own text (max 40 characters); `label_position` picks the corner (`"bottom-right"` default, `"bottom-left"`, `"top-right"`, `"top-left"`).
|
|
33
|
+
- `client.verify(file, filename=None)` or `client.verify(url=...)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`. Direct uploads are limited to about 4.5 MB; pass a public `url` (up to 25 MB) for bigger files, such as marked audio, which comes back as WAV (e.g. a batch item's `file_url`).
|
|
34
|
+
- `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
|
|
35
|
+
|
|
36
|
+
All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
|
|
37
|
+
|
|
38
|
+
## Batches and webhooks
|
|
39
|
+
|
|
40
|
+
For volume, queue many files at once instead of calling `mark` per file. Each item counts as one mark.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
created = client.create_batch(
|
|
44
|
+
urls=["https://cdn.example.com/1.png", "https://cdn.example.com/2.png"], # and/or files=["a.png", (data, "b.wav")]
|
|
45
|
+
generator_name="your-app",
|
|
46
|
+
webhook_url="https://your-app.example.com/hooks/markproof", # optional
|
|
47
|
+
)
|
|
48
|
+
batch = client.wait_for_batch(created.batch_id) # or get_batch(...), or wait for the webhook
|
|
49
|
+
for item in batch.items:
|
|
50
|
+
print(item.index, item.status, item.file_url or item.error)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `client.create_batch(files=None, urls=None, generator_name=None, model_name=None, webhook_url=None)` → `CreatedBatch` — files go up in one multipart request (keep the total under ~4.5 MB; use `urls` for more). Max items per batch: 10 Free, 100 Indie, 1,000 Pro.
|
|
54
|
+
- `client.get_batch(batch_id)` → `Batch` — `status` (`queued`/`processing`/`completed`/`partial`/`failed`), `counts`, and `items` with `asset_id`, `watermark_code`, `verify_url`, `file_url` (signed, ~1 hour; call again for a fresh one) or `error`.
|
|
55
|
+
- `client.wait_for_batch(batch_id, interval=3.0, timeout=900, on_progress=None)` — polls until the batch is final.
|
|
56
|
+
|
|
57
|
+
Verify webhooks with the raw request body and your signing secret from the dashboard:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from markproof import verify_webhook_signature
|
|
61
|
+
|
|
62
|
+
ok = verify_webhook_signature(
|
|
63
|
+
request.get_data(), # the exact bytes received, not re-serialized JSON
|
|
64
|
+
request.headers.get("Markproof-Signature"),
|
|
65
|
+
os.environ["MARKPROOF_WEBHOOK_SECRET"],
|
|
66
|
+
)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`parse_webhook_event(...)` does the same and returns the `batch.completed` event, raising `WebhookSignatureError` if the signature doesn't match. Event `id`s are stable across retries, so use them to drop duplicates.
|
|
@@ -198,14 +198,26 @@ class Markproof:
|
|
|
198
198
|
file=response.content,
|
|
199
199
|
)
|
|
200
200
|
|
|
201
|
-
def verify(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
201
|
+
def verify(
|
|
202
|
+
self, file: Optional[FileLike] = None, filename: Optional[str] = None, *, url: Optional[str] = None
|
|
203
|
+
) -> VerifyResult:
|
|
204
|
+
"""Checks a file for our watermark and/or a C2PA manifest.
|
|
205
|
+
|
|
206
|
+
Pass ``url`` instead of ``file`` for anything over ~4.5 MB (the
|
|
207
|
+
direct-upload limit), e.g. marked audio, which comes back as WAV;
|
|
208
|
+
URLs up to 25 MB work.
|
|
209
|
+
"""
|
|
210
|
+
if (file is None) == (url is None):
|
|
211
|
+
raise ValueError("Pass exactly one of file or url.")
|
|
212
|
+
if url is not None:
|
|
213
|
+
response = self._session.post(f"{self._base_url}/verify", headers=self._headers(), json={"url": url})
|
|
214
|
+
else:
|
|
215
|
+
data, resolved_filename, content_type = _resolve_file(file, filename)
|
|
216
|
+
response = self._session.post(
|
|
217
|
+
f"{self._base_url}/verify",
|
|
218
|
+
headers=self._headers(),
|
|
219
|
+
files={"file": (resolved_filename, data, content_type)},
|
|
220
|
+
)
|
|
209
221
|
self._raise_if_error(response)
|
|
210
222
|
body = response.json()
|
|
211
223
|
return VerifyResult(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: markproof
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python client for the Markproof API - EU AI Act Article 50 watermarking and verification.
|
|
5
5
|
Author-email: Markproof <support@markproof.co>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -49,7 +49,7 @@ print(result.summary)
|
|
|
49
49
|
|
|
50
50
|
- `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
|
|
51
51
|
- `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file", visible_label=None, label_position=None)` → `MarkResult` — `file` is a path (`str`/`os.PathLike`) or raw `bytes` (in which case `filename` is required). `response_format="file"` (default) returns the marked bytes inline (`result.file`/`result.content_type`); `"url"` returns a short-lived signed download URL instead (`result.file_url`, ~1 hour — download promptly rather than caching it). Either way you also get `asset_id`, `watermark_code`, `verify_url`, `c2pa_manifest_label`. `visible_label` (images only): `True` draws a visible "AI-generated" label (EU AI Act Art. 50(4)) before marking, or pass your own text (max 40 characters); `label_position` picks the corner (`"bottom-right"` default, `"bottom-left"`, `"top-right"`, `"top-left"`).
|
|
52
|
-
- `client.verify(file, filename=None)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`.
|
|
52
|
+
- `client.verify(file, filename=None)` or `client.verify(url=...)` → `VerifyResult` — `watermark`/`c2pa` detection results, `matched_asset` if the watermark matches a record in Markproof's database, and a human-readable `summary`. Direct uploads are limited to about 4.5 MB; pass a public `url` (up to 25 MB) for bigger files, such as marked audio, which comes back as WAV (e.g. a batch item's `file_url`).
|
|
53
53
|
- `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
|
|
54
54
|
|
|
55
55
|
All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
|
|
@@ -1,249 +1,278 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"x-
|
|
38
|
-
"x-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
assert result.
|
|
47
|
-
assert result.
|
|
48
|
-
assert result.
|
|
49
|
-
assert result.
|
|
50
|
-
assert result.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"x-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
assert result.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
assert result.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
assert result.
|
|
199
|
-
assert result.
|
|
200
|
-
assert result.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
"
|
|
212
|
-
"
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
assert
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
import responses
|
|
5
|
+
|
|
6
|
+
from markproof import Markproof, MarkproofError
|
|
7
|
+
|
|
8
|
+
API_KEY = "lt_test_abc123"
|
|
9
|
+
BASE_URL = "http://localhost:3000/api/v1"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def client():
|
|
14
|
+
return Markproof(api_key=API_KEY, base_url=BASE_URL)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_requires_api_key():
|
|
18
|
+
with pytest.raises(ValueError, match="api_key is required"):
|
|
19
|
+
Markproof(api_key="")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_strips_trailing_slash():
|
|
23
|
+
client = Markproof(api_key=API_KEY, base_url="http://localhost:3000/api/v1/")
|
|
24
|
+
assert client._base_url == "http://localhost:3000/api/v1"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@responses.activate
|
|
28
|
+
def test_mark_parses_binary_response_and_headers(client):
|
|
29
|
+
file_bytes = b"\x01\x02\x03\x04"
|
|
30
|
+
responses.add(
|
|
31
|
+
responses.POST,
|
|
32
|
+
f"{BASE_URL}/mark",
|
|
33
|
+
body=file_bytes,
|
|
34
|
+
status=200,
|
|
35
|
+
content_type="image/png",
|
|
36
|
+
headers={
|
|
37
|
+
"x-asset-id": "asset-1",
|
|
38
|
+
"x-watermark-code": "ABC12345",
|
|
39
|
+
"x-verify-url": "https://markproof.co/v/ABC12345",
|
|
40
|
+
"x-c2pa-manifest-label": "urn:c2pa:xyz",
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
result = client.mark(file_bytes, filename="test.png")
|
|
45
|
+
|
|
46
|
+
assert result.content_type == "image/png"
|
|
47
|
+
assert result.asset_id == "asset-1"
|
|
48
|
+
assert result.watermark_code == "ABC12345"
|
|
49
|
+
assert result.kind == "image"
|
|
50
|
+
assert result.verify_url == "https://markproof.co/v/ABC12345"
|
|
51
|
+
assert result.c2pa_manifest_label == "urn:c2pa:xyz"
|
|
52
|
+
assert result.file == file_bytes
|
|
53
|
+
|
|
54
|
+
sent = responses.calls[0].request
|
|
55
|
+
assert sent.headers["Authorization"] == f"Bearer {API_KEY}"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@responses.activate
|
|
59
|
+
def test_mark_requires_filename_for_raw_bytes(client):
|
|
60
|
+
with pytest.raises(ValueError, match="filename is required"):
|
|
61
|
+
client.mark(b"abc")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@responses.activate
|
|
65
|
+
def test_mark_detects_audio_from_content_type(client):
|
|
66
|
+
responses.add(
|
|
67
|
+
responses.POST,
|
|
68
|
+
f"{BASE_URL}/mark",
|
|
69
|
+
body=b"\x00",
|
|
70
|
+
status=200,
|
|
71
|
+
content_type="audio/wav",
|
|
72
|
+
headers={
|
|
73
|
+
"x-asset-id": "a",
|
|
74
|
+
"x-watermark-code": "b",
|
|
75
|
+
"x-verify-url": "c",
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
result = client.mark(b"fake-wav-bytes", filename="test.wav")
|
|
79
|
+
assert result.content_type == "audio/wav"
|
|
80
|
+
assert result.kind == "audio"
|
|
81
|
+
# Audio isn't self-checked, so the API omits the header.
|
|
82
|
+
assert result.watermark_robust is None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@responses.activate
|
|
86
|
+
def test_mark_parses_watermark_robust_header(client):
|
|
87
|
+
responses.add(
|
|
88
|
+
responses.POST,
|
|
89
|
+
f"{BASE_URL}/mark",
|
|
90
|
+
body=b"\x00",
|
|
91
|
+
status=200,
|
|
92
|
+
content_type="image/png",
|
|
93
|
+
headers={"x-asset-id": "a", "x-watermark-code": "b", "x-verify-url": "c", "x-watermark-robust": "false"},
|
|
94
|
+
)
|
|
95
|
+
assert client.mark(b"img", filename="x.png").watermark_robust is False
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@responses.activate
|
|
99
|
+
def test_mark_raises_markproof_error_with_server_message(client):
|
|
100
|
+
responses.add(
|
|
101
|
+
responses.POST,
|
|
102
|
+
f"{BASE_URL}/mark",
|
|
103
|
+
json={"error": "Monthly quota exceeded (10/10)."},
|
|
104
|
+
status=429,
|
|
105
|
+
)
|
|
106
|
+
with pytest.raises(MarkproofError) as exc_info:
|
|
107
|
+
client.mark(b"abc", filename="test.png")
|
|
108
|
+
assert exc_info.value.status == 429
|
|
109
|
+
assert str(exc_info.value) == "Monthly quota exceeded (10/10)."
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@responses.activate
|
|
113
|
+
def test_mark_with_response_format_url(client):
|
|
114
|
+
responses.add(
|
|
115
|
+
responses.POST,
|
|
116
|
+
f"{BASE_URL}/mark",
|
|
117
|
+
json={
|
|
118
|
+
"asset_id": "asset-1",
|
|
119
|
+
"watermark_code": "ABC12345",
|
|
120
|
+
"kind": "image",
|
|
121
|
+
"verify_url": "https://markproof.co/v/ABC12345",
|
|
122
|
+
"c2pa_manifest_label": "urn:c2pa:xyz",
|
|
123
|
+
"file_url": "https://storage.example/signed-url",
|
|
124
|
+
},
|
|
125
|
+
status=200,
|
|
126
|
+
)
|
|
127
|
+
result = client.mark(b"abc", filename="test.png", response_format="url")
|
|
128
|
+
|
|
129
|
+
assert result.file_url == "https://storage.example/signed-url"
|
|
130
|
+
assert result.file is None
|
|
131
|
+
assert result.asset_id == "asset-1"
|
|
132
|
+
|
|
133
|
+
sent = responses.calls[0].request
|
|
134
|
+
assert b'name="response_format"' in sent.body
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _ok_image_response():
|
|
138
|
+
responses.add(
|
|
139
|
+
responses.POST,
|
|
140
|
+
f"{BASE_URL}/mark",
|
|
141
|
+
body=b"\x00",
|
|
142
|
+
status=200,
|
|
143
|
+
content_type="image/png",
|
|
144
|
+
headers={"x-asset-id": "a", "x-watermark-code": "b", "x-verify-url": "c"},
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@responses.activate
|
|
149
|
+
def test_mark_sends_visible_label_true_and_position(client):
|
|
150
|
+
_ok_image_response()
|
|
151
|
+
client.mark(b"img", filename="x.png", visible_label=True, label_position="top-left")
|
|
152
|
+
body = responses.calls[0].request.body
|
|
153
|
+
assert b'name="visible_label"\r\n\r\ntrue\r\n' in body
|
|
154
|
+
assert b'name="label_position"\r\n\r\ntop-left\r\n' in body
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@responses.activate
|
|
158
|
+
def test_mark_sends_custom_visible_label(client):
|
|
159
|
+
_ok_image_response()
|
|
160
|
+
client.mark(b"img", filename="x.png", visible_label="Généré par IA")
|
|
161
|
+
body = responses.calls[0].request.body
|
|
162
|
+
assert 'name="visible_label"\r\n\r\nGénéré par IA\r\n'.encode() in body
|
|
163
|
+
assert b'name="label_position"' not in body
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@responses.activate
|
|
167
|
+
def test_mark_omits_label_fields_by_default(client):
|
|
168
|
+
_ok_image_response()
|
|
169
|
+
client.mark(b"img", filename="x.png", label_position="top-left")
|
|
170
|
+
body = responses.calls[0].request.body
|
|
171
|
+
assert b'name="visible_label"' not in body
|
|
172
|
+
assert b'name="label_position"' not in body
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@responses.activate
|
|
176
|
+
def test_verify_converts_snake_case_response(client):
|
|
177
|
+
responses.add(
|
|
178
|
+
responses.POST,
|
|
179
|
+
f"{BASE_URL}/verify",
|
|
180
|
+
json={
|
|
181
|
+
"watermark": {"detected": True, "watermark_code": "ABC12345", "confidence": None},
|
|
182
|
+
"c2pa": {"present": True, "signature_valid": True, "trusted": False, "manifest_label": "urn:c2pa:xyz"},
|
|
183
|
+
"matched_asset": {
|
|
184
|
+
"id": "asset-1",
|
|
185
|
+
"watermark_code": "ABC12345",
|
|
186
|
+
"kind": "image",
|
|
187
|
+
"generator_name": "midjourney",
|
|
188
|
+
"model_name": "v7",
|
|
189
|
+
"c2pa_manifest_label": "urn:c2pa:xyz",
|
|
190
|
+
"created_at": "2026-10-25T00:00:00Z",
|
|
191
|
+
},
|
|
192
|
+
"summary": "Watermark detected code ABC12345, matches our record.",
|
|
193
|
+
},
|
|
194
|
+
status=200,
|
|
195
|
+
)
|
|
196
|
+
result = client.verify(b"abc", filename="test.png")
|
|
197
|
+
|
|
198
|
+
assert result.watermark.detected is True
|
|
199
|
+
assert result.watermark.watermark_code == "ABC12345"
|
|
200
|
+
assert result.c2pa.trusted is False
|
|
201
|
+
assert result.matched_asset is not None
|
|
202
|
+
assert result.matched_asset.generator_name == "midjourney"
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@responses.activate
|
|
206
|
+
def test_verify_handles_no_matched_asset(client):
|
|
207
|
+
responses.add(
|
|
208
|
+
responses.POST,
|
|
209
|
+
f"{BASE_URL}/verify",
|
|
210
|
+
json={
|
|
211
|
+
"watermark": {"detected": False, "watermark_code": None, "confidence": None},
|
|
212
|
+
"c2pa": {"present": False, "signature_valid": None, "trusted": None, "manifest_label": None},
|
|
213
|
+
"matched_asset": None,
|
|
214
|
+
"summary": "No watermark detected.",
|
|
215
|
+
},
|
|
216
|
+
status=200,
|
|
217
|
+
)
|
|
218
|
+
result = client.verify(b"abc", filename="test.png")
|
|
219
|
+
assert result.matched_asset is None
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@responses.activate
|
|
223
|
+
def test_verify_by_url_sends_json(client):
|
|
224
|
+
responses.add(
|
|
225
|
+
responses.POST,
|
|
226
|
+
f"{BASE_URL}/verify",
|
|
227
|
+
json={
|
|
228
|
+
"watermark": {"detected": True, "watermark_code": None, "confidence": 0.98},
|
|
229
|
+
"c2pa": {"present": True, "signature_valid": True, "trusted": False, "manifest_label": "urn:c2pa:x"},
|
|
230
|
+
"matched_asset": None,
|
|
231
|
+
"summary": "Watermark detected.",
|
|
232
|
+
},
|
|
233
|
+
status=200,
|
|
234
|
+
)
|
|
235
|
+
result = client.verify(url="https://cdn.example.com/a.wav")
|
|
236
|
+
sent = responses.calls[0].request
|
|
237
|
+
assert sent.headers["Content-Type"] == "application/json"
|
|
238
|
+
assert json.loads(sent.body) == {"url": "https://cdn.example.com/a.wav"}
|
|
239
|
+
assert result.watermark.confidence == 0.98
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def test_verify_needs_exactly_one_input(client):
|
|
243
|
+
with pytest.raises(ValueError):
|
|
244
|
+
client.verify()
|
|
245
|
+
with pytest.raises(ValueError):
|
|
246
|
+
client.verify(b"abc", url="https://cdn.example.com/a.wav")
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
@responses.activate
|
|
250
|
+
def test_get_asset(client):
|
|
251
|
+
responses.add(
|
|
252
|
+
responses.GET,
|
|
253
|
+
f"{BASE_URL}/assets/asset-1",
|
|
254
|
+
json={
|
|
255
|
+
"id": "asset-1",
|
|
256
|
+
"watermark_code": "ABC12345",
|
|
257
|
+
"kind": "image",
|
|
258
|
+
"generator_name": None,
|
|
259
|
+
"model_name": None,
|
|
260
|
+
"c2pa_manifest_label": None,
|
|
261
|
+
"created_at": "2026-10-25T00:00:00Z",
|
|
262
|
+
},
|
|
263
|
+
status=200,
|
|
264
|
+
)
|
|
265
|
+
asset = client.get_asset("asset-1")
|
|
266
|
+
assert asset.id == "asset-1"
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@responses.activate
|
|
270
|
+
def test_get_asset_url_encodes_id(client):
|
|
271
|
+
responses.add(
|
|
272
|
+
responses.GET,
|
|
273
|
+
f"{BASE_URL}/assets/weird%2Fid",
|
|
274
|
+
json={"error": "Not found."},
|
|
275
|
+
status=404,
|
|
276
|
+
)
|
|
277
|
+
with pytest.raises(MarkproofError):
|
|
278
|
+
client.get_asset("weird/id")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|