markproof 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -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
+ ]
markproof/client.py ADDED
@@ -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())
markproof/errors.py ADDED
@@ -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,8 @@
1
+ markproof/__init__.py,sha256=r4fMUXj_DH2Jk6EeOJwoR-q9ls6wPWvlsWqfTJ5gKYE,273
2
+ markproof/client.py,sha256=o17q8nP5VsnA5HfkTap3_YwIy0YxJvUP7zWmMQUwZ-o,7603
3
+ markproof/errors.py,sha256=ye2wlKTKNT0JsqcSJRZkJXnsTd7AdSgD1SGHuY6lmkw,260
4
+ markproof-0.1.0.dist-info/licenses/LICENSE,sha256=qHkBJ7R1C-NikKCO2yIm2FzGjbrcWlhZ3T32kkr78QA,1090
5
+ markproof-0.1.0.dist-info/METADATA,sha256=pIKA8Baxf8BVnCRTXPAER7zdpc8aiSOAHYZcrSvvbDY,2465
6
+ markproof-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ markproof-0.1.0.dist-info/top_level.txt,sha256=zeeGoE9_onU8yR0Qdm6awArjJh1xfcXspuFv7_lvsfM,10
8
+ markproof-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -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 @@
1
+ markproof