enconvert 0.0.1__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.
enconvert/__init__.py ADDED
@@ -0,0 +1,143 @@
1
+ """Enconvert — Python SDK for the Enconvert file conversion API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .client import Enconvert
6
+ from .errors import (
7
+ APIError,
8
+ AuthenticationError,
9
+ EnconvertError,
10
+ QuotaError,
11
+ RateLimitError,
12
+ )
13
+ from .formats import IMPLEMENTED_CONVERSIONS, valid_outputs_for
14
+ from .types import (
15
+ BatchItem,
16
+ BatchStatus,
17
+ BatchStatusValue,
18
+ BatchSubmission,
19
+ BrowserCookie,
20
+ ConversionResult,
21
+ CrawlMode,
22
+ CssField,
23
+ CssFieldType,
24
+ CssSchema,
25
+ DiscoverMode,
26
+ DiscoverResult,
27
+ DistillDiscoverFrom,
28
+ DistillExtractionTier,
29
+ DistillItem,
30
+ DistillResult,
31
+ FileData,
32
+ FileInput,
33
+ HttpBasicAuth,
34
+ IngestChunkOptions,
35
+ IngestJob,
36
+ IngestJobList,
37
+ IngestJobSummary,
38
+ IngestMode,
39
+ IngestStatus,
40
+ JobStatus,
41
+ JobStatusValue,
42
+ LookupCategory,
43
+ LookupItem,
44
+ LookupResult,
45
+ LookupTimeFilter,
46
+ PdfHeaderFooter,
47
+ PdfMargins,
48
+ PdfOptions,
49
+ PerceiveBatchOutputMode,
50
+ PerceiveBatchResult,
51
+ PerceiveBatchStatus,
52
+ PerceiveCacheMode,
53
+ PerceiveExtractName,
54
+ PerceiveExtractionTier,
55
+ PerceiveOutputName,
56
+ PerceiveResourceType,
57
+ PerceiveResult,
58
+ PerceiveStatus,
59
+ PerceiveViewport,
60
+ V2OutputArtifact,
61
+ V2Tokens,
62
+ WatchDiffMode,
63
+ Watcher,
64
+ WatcherList,
65
+ WatcherSnapshot,
66
+ WatcherSnapshotList,
67
+ WatcherStatus,
68
+ WatcherSummary,
69
+ WebhookRetryResult,
70
+ WebhookSecret,
71
+ )
72
+ from .v2 import EnconvertV2
73
+
74
+ __version__ = "0.0.1"
75
+
76
+ __all__ = [
77
+ "Enconvert",
78
+ "EnconvertV2",
79
+ "EnconvertError",
80
+ "APIError",
81
+ "AuthenticationError",
82
+ "QuotaError",
83
+ "RateLimitError",
84
+ "IMPLEMENTED_CONVERSIONS",
85
+ "valid_outputs_for",
86
+ "BatchItem",
87
+ "BatchStatus",
88
+ "BatchStatusValue",
89
+ "BatchSubmission",
90
+ "BrowserCookie",
91
+ "ConversionResult",
92
+ "CrawlMode",
93
+ "CssField",
94
+ "CssFieldType",
95
+ "CssSchema",
96
+ "DiscoverMode",
97
+ "DiscoverResult",
98
+ "DistillDiscoverFrom",
99
+ "DistillExtractionTier",
100
+ "DistillItem",
101
+ "DistillResult",
102
+ "FileData",
103
+ "FileInput",
104
+ "HttpBasicAuth",
105
+ "IngestChunkOptions",
106
+ "IngestJob",
107
+ "IngestJobList",
108
+ "IngestJobSummary",
109
+ "IngestMode",
110
+ "IngestStatus",
111
+ "JobStatus",
112
+ "JobStatusValue",
113
+ "LookupCategory",
114
+ "LookupItem",
115
+ "LookupResult",
116
+ "LookupTimeFilter",
117
+ "PdfHeaderFooter",
118
+ "PdfMargins",
119
+ "PdfOptions",
120
+ "PerceiveBatchOutputMode",
121
+ "PerceiveBatchResult",
122
+ "PerceiveBatchStatus",
123
+ "PerceiveCacheMode",
124
+ "PerceiveExtractName",
125
+ "PerceiveExtractionTier",
126
+ "PerceiveOutputName",
127
+ "PerceiveResourceType",
128
+ "PerceiveResult",
129
+ "PerceiveStatus",
130
+ "PerceiveViewport",
131
+ "V2OutputArtifact",
132
+ "V2Tokens",
133
+ "WatchDiffMode",
134
+ "Watcher",
135
+ "WatcherList",
136
+ "WatcherSnapshot",
137
+ "WatcherSnapshotList",
138
+ "WatcherStatus",
139
+ "WatcherSummary",
140
+ "WebhookRetryResult",
141
+ "WebhookSecret",
142
+ "__version__",
143
+ ]
enconvert/_internal.py ADDED
@@ -0,0 +1,127 @@
1
+ """Shared internal helpers used by both the V1 client and the V2 namespace."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+ from typing import Any, Dict, Optional, Protocol
7
+
8
+ import requests
9
+
10
+ from .errors import APIError, AuthenticationError, QuotaError, RateLimitError
11
+ from .types import BrowserCookie, HttpBasicAuth, PdfHeaderFooter, PdfMargins, PdfOptions
12
+
13
+
14
+ class RequestFunc(Protocol):
15
+ """Authenticated, timeout-wrapped request bound to the client's base URL."""
16
+
17
+ def __call__(
18
+ self,
19
+ path: str,
20
+ method: str,
21
+ *,
22
+ json_body: Optional[Dict[str, Any]] = None,
23
+ data: Optional[Dict[str, Any]] = None,
24
+ files: Optional[Dict[str, Any]] = None,
25
+ ) -> requests.Response: ...
26
+
27
+
28
+ def raise_for_status(resp: requests.Response) -> None:
29
+ """Translate an HTTP error response into the SDK's exception hierarchy."""
30
+ if resp.status_code < 400:
31
+ return
32
+ message: str
33
+ try:
34
+ body = resp.json()
35
+ message = (
36
+ (body.get("detail") if isinstance(body, dict) else None)
37
+ or (body.get("error") if isinstance(body, dict) else None)
38
+ or str(body)
39
+ )
40
+ except ValueError:
41
+ message = resp.text or f"HTTP {resp.status_code}"
42
+ if resp.status_code in (401, 403):
43
+ raise AuthenticationError(message)
44
+ if resp.status_code == 402:
45
+ raise QuotaError(message)
46
+ if resp.status_code == 429:
47
+ raise RateLimitError(message)
48
+ raise APIError(resp.status_code, message)
49
+
50
+
51
+ def new_job_id() -> str:
52
+ """A UUID4 hex string with dashes removed (32 hex chars)."""
53
+ return uuid.uuid4().hex
54
+
55
+
56
+ def serialize_pdf_options(o: PdfOptions) -> Dict[str, Any]:
57
+ out: Dict[str, Any] = {}
58
+ if o.page_size is not None:
59
+ out["page_size"] = o.page_size
60
+ if o.page_width is not None:
61
+ out["page_width"] = o.page_width
62
+ if o.page_height is not None:
63
+ out["page_height"] = o.page_height
64
+ if o.orientation is not None:
65
+ out["orientation"] = o.orientation
66
+ if o.margins is not None:
67
+ out["margins"] = serialize_pdf_margins(o.margins)
68
+ if o.scale is not None:
69
+ out["scale"] = o.scale
70
+ if o.grayscale is not None:
71
+ out["grayscale"] = o.grayscale
72
+ if o.header is not None:
73
+ out["header"] = serialize_pdf_header_footer(o.header)
74
+ if o.footer is not None:
75
+ out["footer"] = serialize_pdf_header_footer(o.footer)
76
+ return out
77
+
78
+
79
+ def serialize_pdf_margins(m: PdfMargins) -> Dict[str, Any]:
80
+ out: Dict[str, Any] = {}
81
+ if m.top is not None:
82
+ out["top"] = m.top
83
+ if m.bottom is not None:
84
+ out["bottom"] = m.bottom
85
+ if m.left is not None:
86
+ out["left"] = m.left
87
+ if m.right is not None:
88
+ out["right"] = m.right
89
+ return out
90
+
91
+
92
+ def serialize_pdf_header_footer(hf: PdfHeaderFooter) -> Dict[str, Any]:
93
+ out: Dict[str, Any] = {}
94
+ if hf.content is not None:
95
+ out["content"] = hf.content
96
+ if hf.height is not None:
97
+ out["height"] = hf.height
98
+ return out
99
+
100
+
101
+ def serialize_http_basic_auth(a: HttpBasicAuth) -> Dict[str, Any]:
102
+ return {"username": a.username, "password": a.password}
103
+
104
+
105
+ def serialize_cookie(c: BrowserCookie) -> Dict[str, Any]:
106
+ """
107
+ Serialize a BrowserCookie to the wire shape. Field names here mirror
108
+ Playwright's cookie schema (which the gateway forwards these to
109
+ verbatim), so `http_only`/`same_site` map to the camelCase wire keys
110
+ `httpOnly`/`sameSite` while every other key stays as-is.
111
+ """
112
+ out: Dict[str, Any] = {"name": c.name, "value": c.value}
113
+ if c.domain is not None:
114
+ out["domain"] = c.domain
115
+ if c.url is not None:
116
+ out["url"] = c.url
117
+ if c.path is not None:
118
+ out["path"] = c.path
119
+ if c.expires is not None:
120
+ out["expires"] = c.expires
121
+ if c.http_only is not None:
122
+ out["httpOnly"] = c.http_only
123
+ if c.secure is not None:
124
+ out["secure"] = c.secure
125
+ if c.same_site is not None:
126
+ out["sameSite"] = c.same_site
127
+ return out