markproof 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ajinkya Buva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: markproof
3
+ Version: 0.1.0
4
+ Summary: Python client for the Markproof API - EU AI Act Article 50 watermarking and verification.
5
+ Author-email: Markproof <support@markproof.co>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://markproof.co
8
+ Project-URL: Documentation, https://markproof.co/docs
9
+ Keywords: eu-ai-act,article-50,watermark,c2pa,content-credentials,ai-generated,provenance
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Multimedia :: Graphics
13
+ Classifier: Topic :: Multimedia :: Sound/Audio
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests>=2.31
18
+ Dynamic: license-file
19
+
20
+ # markproof
21
+
22
+ Python client for the [Markproof](https://markproof.co) API — EU AI Act Article 50 watermarking and verification in one call. Thin wrapper over `requests`.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install markproof
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ from markproof import Markproof
34
+
35
+ client = Markproof(api_key="lt_live_...")
36
+
37
+ marked = client.mark("generated.png", generator_name="my-app", model_name="my-model-v1")
38
+ print(marked.watermark_code, marked.verify_url)
39
+ with open("generated-marked.png", "wb") as f:
40
+ f.write(marked.file)
41
+
42
+ result = client.verify("generated-marked.png")
43
+ print(result.summary)
44
+ ```
45
+
46
+ ## API
47
+
48
+ - `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
49
+ - `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file")` → `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`.
50
+ - `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`.
51
+ - `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
52
+
53
+ All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
@@ -0,0 +1,34 @@
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
+ ## Install
6
+
7
+ ```bash
8
+ pip install markproof
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from markproof import Markproof
15
+
16
+ client = Markproof(api_key="lt_live_...")
17
+
18
+ marked = client.mark("generated.png", generator_name="my-app", model_name="my-model-v1")
19
+ print(marked.watermark_code, marked.verify_url)
20
+ with open("generated-marked.png", "wb") as f:
21
+ f.write(marked.file)
22
+
23
+ result = client.verify("generated-marked.png")
24
+ print(result.summary)
25
+ ```
26
+
27
+ ## API
28
+
29
+ - `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
30
+ - `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file")` → `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`.
31
+ - `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`.
32
+ - `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
33
+
34
+ All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
@@ -0,0 +1,12 @@
1
+ from .client import Asset, C2paResult, MarkResult, Markproof, VerifyResult, WatermarkResult
2
+ from .errors import MarkproofError
3
+
4
+ __all__ = [
5
+ "Markproof",
6
+ "MarkproofError",
7
+ "MarkResult",
8
+ "VerifyResult",
9
+ "WatermarkResult",
10
+ "C2paResult",
11
+ "Asset",
12
+ ]
@@ -0,0 +1,210 @@
1
+ """Python client for the Markproof API. See README.md for usage."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import mimetypes
6
+ import os
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+ from typing import Optional, Union
10
+ from urllib.parse import quote
11
+
12
+ import requests
13
+
14
+ from .errors import MarkproofError
15
+
16
+ DEFAULT_BASE_URL = "https://markproof.co/v1"
17
+
18
+ FileLike = Union[str, "os.PathLike[str]", bytes]
19
+
20
+
21
+ @dataclass
22
+ class MarkResult:
23
+ asset_id: str
24
+ watermark_code: str
25
+ kind: str # "image" | "audio"
26
+ verify_url: str
27
+ c2pa_manifest_label: Optional[str]
28
+ # Images only (None for audio): whether the watermark passed Markproof's
29
+ # robustness self-check. False for rare, very smooth images - the file is
30
+ # still marked and signed, but rely on the C2PA manifest for it.
31
+ watermark_robust: Optional[bool] = None
32
+ # Exactly one pair is populated, matching the requested response_format.
33
+ content_type: Optional[str] = None
34
+ file: Optional[bytes] = None
35
+ # Populated when response_format="url". Short-lived (~1 hour) - download
36
+ # promptly rather than caching it.
37
+ file_url: Optional[str] = None
38
+
39
+
40
+ @dataclass
41
+ class WatermarkResult:
42
+ detected: bool
43
+ watermark_code: Optional[str]
44
+ confidence: Optional[float]
45
+
46
+
47
+ @dataclass
48
+ class C2paResult:
49
+ present: bool
50
+ signature_valid: Optional[bool]
51
+ trusted: Optional[bool]
52
+ manifest_label: Optional[str]
53
+
54
+
55
+ @dataclass
56
+ class Asset:
57
+ id: str
58
+ watermark_code: str
59
+ kind: str
60
+ generator_name: Optional[str]
61
+ model_name: Optional[str]
62
+ c2pa_manifest_label: Optional[str]
63
+ created_at: str
64
+
65
+
66
+ @dataclass
67
+ class VerifyResult:
68
+ watermark: WatermarkResult
69
+ c2pa: C2paResult
70
+ matched_asset: Optional[Asset]
71
+ summary: str
72
+
73
+
74
+ def _asset_from_api(body: dict) -> Asset:
75
+ return Asset(
76
+ id=body["id"],
77
+ watermark_code=body["watermark_code"],
78
+ kind=body["kind"],
79
+ generator_name=body.get("generator_name"),
80
+ model_name=body.get("model_name"),
81
+ c2pa_manifest_label=body.get("c2pa_manifest_label"),
82
+ created_at=body["created_at"],
83
+ )
84
+
85
+
86
+ def _resolve_file(file: FileLike, filename: Optional[str]) -> tuple[bytes, str, str]:
87
+ """Returns (data, filename, content_type)."""
88
+ if isinstance(file, (bytes, bytearray)):
89
+ if not filename:
90
+ raise ValueError("filename is required when passing raw bytes.")
91
+ data = bytes(file)
92
+ else:
93
+ path = Path(file)
94
+ data = path.read_bytes()
95
+ filename = filename or path.name
96
+ content_type = mimetypes.guess_type(filename)[0] or "application/octet-stream"
97
+ return data, filename, content_type
98
+
99
+
100
+ class Markproof:
101
+ def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL):
102
+ if not api_key:
103
+ raise ValueError("Markproof: api_key is required.")
104
+ self._api_key = api_key
105
+ self._base_url = base_url.rstrip("/")
106
+ self._session = requests.Session()
107
+
108
+ def _headers(self) -> dict:
109
+ return {"Authorization": f"Bearer {self._api_key}"}
110
+
111
+ def _raise_if_error(self, response: requests.Response) -> None:
112
+ if response.ok:
113
+ return
114
+ try:
115
+ body = response.json()
116
+ except ValueError:
117
+ body = response.text
118
+ message = (
119
+ body["error"]
120
+ if isinstance(body, dict) and isinstance(body.get("error"), str)
121
+ else f"Markproof API error (status {response.status_code})"
122
+ )
123
+ raise MarkproofError(message, response.status_code, body)
124
+
125
+ def mark(
126
+ self,
127
+ file: FileLike,
128
+ filename: Optional[str] = None,
129
+ generator_name: Optional[str] = None,
130
+ model_name: Optional[str] = None,
131
+ response_format: str = "file",
132
+ ) -> MarkResult:
133
+ """Watermarks (and, if the server has C2PA signing configured, signs) a file.
134
+
135
+ response_format="file" (default) returns the marked bytes inline
136
+ (result.file/result.content_type). "url" returns a short-lived
137
+ signed download URL instead (result.file_url).
138
+ """
139
+ data, resolved_filename, content_type = _resolve_file(file, filename)
140
+ form_data = {}
141
+ if generator_name:
142
+ form_data["generator_name"] = generator_name
143
+ if model_name:
144
+ form_data["model_name"] = model_name
145
+ if response_format == "url":
146
+ form_data["response_format"] = "url"
147
+
148
+ response = self._session.post(
149
+ f"{self._base_url}/mark",
150
+ headers=self._headers(),
151
+ files={"file": (resolved_filename, data, content_type)},
152
+ data=form_data,
153
+ )
154
+ self._raise_if_error(response)
155
+
156
+ if response_format == "url":
157
+ body = response.json()
158
+ return MarkResult(
159
+ asset_id=body["asset_id"],
160
+ watermark_code=body["watermark_code"],
161
+ kind=body["kind"],
162
+ verify_url=body["verify_url"],
163
+ c2pa_manifest_label=body.get("c2pa_manifest_label"),
164
+ watermark_robust=body.get("watermark_robust"),
165
+ file_url=body["file_url"],
166
+ )
167
+
168
+ response_content_type = response.headers.get("content-type", "")
169
+ return MarkResult(
170
+ asset_id=response.headers.get("x-asset-id", ""),
171
+ watermark_code=response.headers.get("x-watermark-code", ""),
172
+ kind="audio" if response_content_type.startswith("audio/") else "image",
173
+ verify_url=response.headers.get("x-verify-url", ""),
174
+ c2pa_manifest_label=response.headers.get("x-c2pa-manifest-label"),
175
+ watermark_robust={"true": True, "false": False}.get(response.headers.get("x-watermark-robust", "")),
176
+ content_type=response_content_type,
177
+ file=response.content,
178
+ )
179
+
180
+ def verify(self, file: FileLike, filename: Optional[str] = None) -> VerifyResult:
181
+ """Checks a file for our watermark and/or a C2PA manifest."""
182
+ data, resolved_filename, content_type = _resolve_file(file, filename)
183
+ response = self._session.post(
184
+ f"{self._base_url}/verify",
185
+ headers=self._headers(),
186
+ files={"file": (resolved_filename, data, content_type)},
187
+ )
188
+ self._raise_if_error(response)
189
+ body = response.json()
190
+ return VerifyResult(
191
+ watermark=WatermarkResult(
192
+ detected=body["watermark"]["detected"],
193
+ watermark_code=body["watermark"].get("watermark_code"),
194
+ confidence=body["watermark"].get("confidence"),
195
+ ),
196
+ c2pa=C2paResult(
197
+ present=body["c2pa"]["present"],
198
+ signature_valid=body["c2pa"].get("signature_valid"),
199
+ trusted=body["c2pa"].get("trusted"),
200
+ manifest_label=body["c2pa"].get("manifest_label"),
201
+ ),
202
+ matched_asset=_asset_from_api(body["matched_asset"]) if body.get("matched_asset") else None,
203
+ summary=body["summary"],
204
+ )
205
+
206
+ def get_asset(self, asset_id: str) -> Asset:
207
+ """Retrieves a previously marked asset's record. Requires a key on the same project that marked it."""
208
+ response = self._session.get(f"{self._base_url}/assets/{quote(asset_id, safe='')}", headers=self._headers())
209
+ self._raise_if_error(response)
210
+ return _asset_from_api(response.json())
@@ -0,0 +1,7 @@
1
+ class MarkproofError(Exception):
2
+ """Raised for any non-2xx response from the Markproof API."""
3
+
4
+ def __init__(self, message: str, status: int, body: object = None):
5
+ super().__init__(message)
6
+ self.status = status
7
+ self.body = body
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: markproof
3
+ Version: 0.1.0
4
+ Summary: Python client for the Markproof API - EU AI Act Article 50 watermarking and verification.
5
+ Author-email: Markproof <support@markproof.co>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://markproof.co
8
+ Project-URL: Documentation, https://markproof.co/docs
9
+ Keywords: eu-ai-act,article-50,watermark,c2pa,content-credentials,ai-generated,provenance
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Multimedia :: Graphics
13
+ Classifier: Topic :: Multimedia :: Sound/Audio
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests>=2.31
18
+ Dynamic: license-file
19
+
20
+ # markproof
21
+
22
+ Python client for the [Markproof](https://markproof.co) API — EU AI Act Article 50 watermarking and verification in one call. Thin wrapper over `requests`.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ pip install markproof
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ from markproof import Markproof
34
+
35
+ client = Markproof(api_key="lt_live_...")
36
+
37
+ marked = client.mark("generated.png", generator_name="my-app", model_name="my-model-v1")
38
+ print(marked.watermark_code, marked.verify_url)
39
+ with open("generated-marked.png", "wb") as f:
40
+ f.write(marked.file)
41
+
42
+ result = client.verify("generated-marked.png")
43
+ print(result.summary)
44
+ ```
45
+
46
+ ## API
47
+
48
+ - `Markproof(api_key, base_url=DEFAULT_BASE_URL)` — `base_url` defaults to the production API; override for local dev.
49
+ - `client.mark(file, filename=None, generator_name=None, model_name=None, response_format="file")` → `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`.
50
+ - `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`.
51
+ - `client.get_asset(asset_id)` → `Asset` — requires an API key on the same project that created the asset.
52
+
53
+ All methods raise `MarkproofError` (with `.status` and `.body`) on a non-2xx response.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ markproof/__init__.py
5
+ markproof/client.py
6
+ markproof/errors.py
7
+ markproof.egg-info/PKG-INFO
8
+ markproof.egg-info/SOURCES.txt
9
+ markproof.egg-info/dependency_links.txt
10
+ markproof.egg-info/requires.txt
11
+ markproof.egg-info/top_level.txt
12
+ tests/test_client.py
@@ -0,0 +1 @@
1
+ requests>=2.31
@@ -0,0 +1 @@
1
+ markproof
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "markproof"
7
+ version = "0.1.0"
8
+ description = "Python client for the Markproof API - EU AI Act Article 50 watermarking and verification."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ authors = [{ name = "Markproof", email = "support@markproof.co" }]
12
+ keywords = ["eu-ai-act", "article-50", "watermark", "c2pa", "content-credentials", "ai-generated", "provenance"]
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
+ "Topic :: Multimedia :: Graphics",
17
+ "Topic :: Multimedia :: Sound/Audio",
18
+ ]
19
+ requires-python = ">=3.9"
20
+ dependencies = [
21
+ "requests>=2.31",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://markproof.co"
26
+ Documentation = "https://markproof.co/docs"
27
+
28
+ [tool.setuptools.packages.find]
29
+ include = ["markproof*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,211 @@
1
+ import pytest
2
+ import responses
3
+
4
+ from markproof import Markproof, MarkproofError
5
+
6
+ API_KEY = "lt_test_abc123"
7
+ BASE_URL = "http://localhost:3000/api/v1"
8
+
9
+
10
+ @pytest.fixture
11
+ def client():
12
+ return Markproof(api_key=API_KEY, base_url=BASE_URL)
13
+
14
+
15
+ def test_requires_api_key():
16
+ with pytest.raises(ValueError, match="api_key is required"):
17
+ Markproof(api_key="")
18
+
19
+
20
+ def test_strips_trailing_slash():
21
+ client = Markproof(api_key=API_KEY, base_url="http://localhost:3000/api/v1/")
22
+ assert client._base_url == "http://localhost:3000/api/v1"
23
+
24
+
25
+ @responses.activate
26
+ def test_mark_parses_binary_response_and_headers(client):
27
+ file_bytes = b"\x01\x02\x03\x04"
28
+ responses.add(
29
+ responses.POST,
30
+ f"{BASE_URL}/mark",
31
+ body=file_bytes,
32
+ status=200,
33
+ content_type="image/png",
34
+ headers={
35
+ "x-asset-id": "asset-1",
36
+ "x-watermark-code": "ABC12345",
37
+ "x-verify-url": "https://markproof.co/v/ABC12345",
38
+ "x-c2pa-manifest-label": "urn:c2pa:xyz",
39
+ },
40
+ )
41
+
42
+ result = client.mark(file_bytes, filename="test.png")
43
+
44
+ assert result.content_type == "image/png"
45
+ assert result.asset_id == "asset-1"
46
+ assert result.watermark_code == "ABC12345"
47
+ assert result.kind == "image"
48
+ assert result.verify_url == "https://markproof.co/v/ABC12345"
49
+ assert result.c2pa_manifest_label == "urn:c2pa:xyz"
50
+ assert result.file == file_bytes
51
+
52
+ sent = responses.calls[0].request
53
+ assert sent.headers["Authorization"] == f"Bearer {API_KEY}"
54
+
55
+
56
+ @responses.activate
57
+ def test_mark_requires_filename_for_raw_bytes(client):
58
+ with pytest.raises(ValueError, match="filename is required"):
59
+ client.mark(b"abc")
60
+
61
+
62
+ @responses.activate
63
+ def test_mark_detects_audio_from_content_type(client):
64
+ responses.add(
65
+ responses.POST,
66
+ f"{BASE_URL}/mark",
67
+ body=b"\x00",
68
+ status=200,
69
+ content_type="audio/wav",
70
+ headers={
71
+ "x-asset-id": "a",
72
+ "x-watermark-code": "b",
73
+ "x-verify-url": "c",
74
+ },
75
+ )
76
+ result = client.mark(b"fake-wav-bytes", filename="test.wav")
77
+ assert result.content_type == "audio/wav"
78
+ assert result.kind == "audio"
79
+ # Audio isn't self-checked, so the API omits the header.
80
+ assert result.watermark_robust is None
81
+
82
+
83
+ @responses.activate
84
+ def test_mark_parses_watermark_robust_header(client):
85
+ responses.add(
86
+ responses.POST,
87
+ f"{BASE_URL}/mark",
88
+ body=b"\x00",
89
+ status=200,
90
+ content_type="image/png",
91
+ headers={"x-asset-id": "a", "x-watermark-code": "b", "x-verify-url": "c", "x-watermark-robust": "false"},
92
+ )
93
+ assert client.mark(b"img", filename="x.png").watermark_robust is False
94
+
95
+
96
+ @responses.activate
97
+ def test_mark_raises_markproof_error_with_server_message(client):
98
+ responses.add(
99
+ responses.POST,
100
+ f"{BASE_URL}/mark",
101
+ json={"error": "Monthly quota exceeded (10/10)."},
102
+ status=429,
103
+ )
104
+ with pytest.raises(MarkproofError) as exc_info:
105
+ client.mark(b"abc", filename="test.png")
106
+ assert exc_info.value.status == 429
107
+ assert str(exc_info.value) == "Monthly quota exceeded (10/10)."
108
+
109
+
110
+ @responses.activate
111
+ def test_mark_with_response_format_url(client):
112
+ responses.add(
113
+ responses.POST,
114
+ f"{BASE_URL}/mark",
115
+ json={
116
+ "asset_id": "asset-1",
117
+ "watermark_code": "ABC12345",
118
+ "kind": "image",
119
+ "verify_url": "https://markproof.co/v/ABC12345",
120
+ "c2pa_manifest_label": "urn:c2pa:xyz",
121
+ "file_url": "https://storage.example/signed-url",
122
+ },
123
+ status=200,
124
+ )
125
+ result = client.mark(b"abc", filename="test.png", response_format="url")
126
+
127
+ assert result.file_url == "https://storage.example/signed-url"
128
+ assert result.file is None
129
+ assert result.asset_id == "asset-1"
130
+
131
+ sent = responses.calls[0].request
132
+ assert b'name="response_format"' in sent.body
133
+
134
+
135
+ @responses.activate
136
+ def test_verify_converts_snake_case_response(client):
137
+ responses.add(
138
+ responses.POST,
139
+ f"{BASE_URL}/verify",
140
+ json={
141
+ "watermark": {"detected": True, "watermark_code": "ABC12345", "confidence": None},
142
+ "c2pa": {"present": True, "signature_valid": True, "trusted": False, "manifest_label": "urn:c2pa:xyz"},
143
+ "matched_asset": {
144
+ "id": "asset-1",
145
+ "watermark_code": "ABC12345",
146
+ "kind": "image",
147
+ "generator_name": "midjourney",
148
+ "model_name": "v7",
149
+ "c2pa_manifest_label": "urn:c2pa:xyz",
150
+ "created_at": "2026-10-25T00:00:00Z",
151
+ },
152
+ "summary": "Watermark detected code ABC12345, matches our record.",
153
+ },
154
+ status=200,
155
+ )
156
+ result = client.verify(b"abc", filename="test.png")
157
+
158
+ assert result.watermark.detected is True
159
+ assert result.watermark.watermark_code == "ABC12345"
160
+ assert result.c2pa.trusted is False
161
+ assert result.matched_asset is not None
162
+ assert result.matched_asset.generator_name == "midjourney"
163
+
164
+
165
+ @responses.activate
166
+ def test_verify_handles_no_matched_asset(client):
167
+ responses.add(
168
+ responses.POST,
169
+ f"{BASE_URL}/verify",
170
+ json={
171
+ "watermark": {"detected": False, "watermark_code": None, "confidence": None},
172
+ "c2pa": {"present": False, "signature_valid": None, "trusted": None, "manifest_label": None},
173
+ "matched_asset": None,
174
+ "summary": "No watermark detected.",
175
+ },
176
+ status=200,
177
+ )
178
+ result = client.verify(b"abc", filename="test.png")
179
+ assert result.matched_asset is None
180
+
181
+
182
+ @responses.activate
183
+ def test_get_asset(client):
184
+ responses.add(
185
+ responses.GET,
186
+ f"{BASE_URL}/assets/asset-1",
187
+ json={
188
+ "id": "asset-1",
189
+ "watermark_code": "ABC12345",
190
+ "kind": "image",
191
+ "generator_name": None,
192
+ "model_name": None,
193
+ "c2pa_manifest_label": None,
194
+ "created_at": "2026-10-25T00:00:00Z",
195
+ },
196
+ status=200,
197
+ )
198
+ asset = client.get_asset("asset-1")
199
+ assert asset.id == "asset-1"
200
+
201
+
202
+ @responses.activate
203
+ def test_get_asset_url_encodes_id(client):
204
+ responses.add(
205
+ responses.GET,
206
+ f"{BASE_URL}/assets/weird%2Fid",
207
+ json={"error": "Not found."},
208
+ status=404,
209
+ )
210
+ with pytest.raises(MarkproofError):
211
+ client.get_asset("weird/id")