Skip to content

Commit 47953f5

Browse files
Create types for remaining Literal arguments in clients
Assisted-by: Codex
1 parent 9c99f33 commit 47953f5

3 files changed

Lines changed: 71 additions & 46 deletions

File tree

src/pdfrest/client.py

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@
107107
)
108108
from .types import (
109109
ALL_PDF_INFO_QUERIES,
110+
BmpColorModel,
111+
CompressionLevel,
112+
ExtractTextGranularity,
113+
FlattenQuality,
114+
GifColorModel,
115+
GraphicSmoothing,
116+
JpegColorModel,
110117
PdfAType,
111118
PdfInfoQuery,
112119
PdfMergeInput,
113120
PdfPageSelection,
114121
PdfRedactionInstruction,
115122
PdfRGBColor,
116123
PdfXType,
124+
PngColorModel,
117125
SummaryFormat,
118126
SummaryOutputFormat,
127+
TiffColorModel,
119128
TranslateOutputFormat,
120129
)
121130

@@ -2392,7 +2401,7 @@ def extract_pdf_text_to_file(
23922401
file: PdfRestFile | Sequence[PdfRestFile],
23932402
*,
23942403
pages: PdfPageSelection | None = None,
2395-
full_text: Literal["off", "by_page", "document"] = "document",
2404+
full_text: ExtractTextGranularity = "document",
23962405
preserve_line_breaks: bool = False,
23972406
word_style: bool = False,
23982407
word_coordinates: bool = False,
@@ -2677,7 +2686,7 @@ def compress_pdf(
26772686
self,
26782687
file: PdfRestFile | Sequence[PdfRestFile],
26792688
*,
2680-
compression_level: Literal["low", "medium", "high", "custom"],
2689+
compression_level: CompressionLevel,
26812690
profile: PdfRestFile | Sequence[PdfRestFile] | None = None,
26822691
output: str | None = None,
26832692
extra_query: Query | None = None,
@@ -2711,7 +2720,7 @@ def flatten_transparencies(
27112720
file: PdfRestFile | Sequence[PdfRestFile],
27122721
*,
27132722
output: str | None = None,
2714-
quality: Literal["low", "medium", "high"] = "medium",
2723+
quality: FlattenQuality = "medium",
27152724
extra_query: Query | None = None,
27162725
extra_headers: AnyMapping | None = None,
27172726
extra_body: Body | None = None,
@@ -2876,10 +2885,8 @@ def convert_to_png(
28762885
output_prefix: str | None = None,
28772886
page_range: str | Sequence[str] | None = None,
28782887
resolution: int = 300,
2879-
color_model: Literal["rgb", "rgba", "gray"] = "rgb",
2880-
smoothing: Literal["none", "all", "text", "line", "image"]
2881-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2882-
| None = None,
2888+
color_model: PngColorModel = "rgb",
2889+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
28832890
extra_query: Query | None = None,
28842891
extra_headers: AnyMapping | None = None,
28852892
extra_body: Body | None = None,
@@ -2916,10 +2923,8 @@ def convert_to_bmp(
29162923
output_prefix: str | None = None,
29172924
page_range: str | Sequence[str] | None = None,
29182925
resolution: int = 300,
2919-
color_model: Literal["rgb", "gray"] = "rgb",
2920-
smoothing: Literal["none", "all", "text", "line", "image"]
2921-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2922-
| None = None,
2926+
color_model: BmpColorModel = "rgb",
2927+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
29232928
extra_query: Query | None = None,
29242929
extra_headers: AnyMapping | None = None,
29252930
extra_body: Body | None = None,
@@ -2956,10 +2961,8 @@ def convert_to_gif(
29562961
output_prefix: str | None = None,
29572962
page_range: str | Sequence[str] | None = None,
29582963
resolution: int = 300,
2959-
color_model: Literal["rgb", "gray"] = "rgb",
2960-
smoothing: Literal["none", "all", "text", "line", "image"]
2961-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2962-
| None = None,
2964+
color_model: GifColorModel = "rgb",
2965+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
29632966
extra_query: Query | None = None,
29642967
extra_headers: AnyMapping | None = None,
29652968
extra_body: Body | None = None,
@@ -2996,10 +2999,8 @@ def convert_to_jpeg(
29962999
output_prefix: str | None = None,
29973000
page_range: str | Sequence[str] | None = None,
29983001
resolution: int = 300,
2999-
color_model: Literal["rgb", "cmyk", "gray"] = "rgb",
3000-
smoothing: Literal["none", "all", "text", "line", "image"]
3001-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3002-
| None = None,
3002+
color_model: JpegColorModel = "rgb",
3003+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
30033004
jpeg_quality: int = 75,
30043005
extra_query: Query | None = None,
30053006
extra_headers: AnyMapping | None = None,
@@ -3038,10 +3039,8 @@ def convert_to_tiff(
30383039
output_prefix: str | None = None,
30393040
page_range: str | Sequence[str] | None = None,
30403041
resolution: int = 300,
3041-
color_model: Literal["rgb", "rgba", "cmyk", "lab", "gray"] = "rgb",
3042-
smoothing: Literal["none", "all", "text", "line", "image"]
3043-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3044-
| None = None,
3042+
color_model: TiffColorModel = "rgb",
3043+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
30453044
extra_query: Query | None = None,
30463045
extra_headers: AnyMapping | None = None,
30473046
extra_body: Body | None = None,
@@ -3401,7 +3400,7 @@ async def extract_pdf_text_to_file(
34013400
file: PdfRestFile | Sequence[PdfRestFile],
34023401
*,
34033402
pages: PdfPageSelection | None = None,
3404-
full_text: Literal["off", "by_page", "document"] = "document",
3403+
full_text: ExtractTextGranularity = "document",
34053404
preserve_line_breaks: bool = False,
34063405
word_style: bool = False,
34073406
word_coordinates: bool = False,
@@ -3728,7 +3727,7 @@ async def compress_pdf(
37283727
self,
37293728
file: PdfRestFile | Sequence[PdfRestFile],
37303729
*,
3731-
compression_level: Literal["low", "medium", "high", "custom"],
3730+
compression_level: CompressionLevel,
37323731
profile: PdfRestFile | Sequence[PdfRestFile] | None = None,
37333732
output: str | None = None,
37343733
extra_query: Query | None = None,
@@ -3762,7 +3761,7 @@ async def flatten_transparencies(
37623761
file: PdfRestFile | Sequence[PdfRestFile],
37633762
*,
37643763
output: str | None = None,
3765-
quality: Literal["low", "medium", "high"] = "medium",
3764+
quality: FlattenQuality = "medium",
37663765
extra_query: Query | None = None,
37673766
extra_headers: AnyMapping | None = None,
37683767
extra_body: Body | None = None,
@@ -3928,10 +3927,8 @@ async def convert_to_png(
39283927
output_prefix: str | None = None,
39293928
page_range: str | Sequence[str] | None = None,
39303929
resolution: int = 300,
3931-
color_model: Literal["rgb", "rgba", "gray"] = "rgb",
3932-
smoothing: Literal["none", "all", "text", "line", "image"]
3933-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3934-
| None = None,
3930+
color_model: PngColorModel = "rgb",
3931+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
39353932
extra_query: Query | None = None,
39363933
extra_headers: AnyMapping | None = None,
39373934
extra_body: Body | None = None,
@@ -3968,10 +3965,8 @@ async def convert_to_bmp(
39683965
output_prefix: str | None = None,
39693966
page_range: str | Sequence[str] | None = None,
39703967
resolution: int = 300,
3971-
color_model: Literal["rgb", "gray"] = "rgb",
3972-
smoothing: Literal["none", "all", "text", "line", "image"]
3973-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3974-
| None = None,
3968+
color_model: BmpColorModel = "rgb",
3969+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
39753970
extra_query: Query | None = None,
39763971
extra_headers: AnyMapping | None = None,
39773972
extra_body: Body | None = None,
@@ -4008,10 +4003,8 @@ async def convert_to_gif(
40084003
output_prefix: str | None = None,
40094004
page_range: str | Sequence[str] | None = None,
40104005
resolution: int = 300,
4011-
color_model: Literal["rgb", "gray"] = "rgb",
4012-
smoothing: Literal["none", "all", "text", "line", "image"]
4013-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4014-
| None = None,
4006+
color_model: GifColorModel = "rgb",
4007+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40154008
extra_query: Query | None = None,
40164009
extra_headers: AnyMapping | None = None,
40174010
extra_body: Body | None = None,
@@ -4048,10 +4041,8 @@ async def convert_to_jpeg(
40484041
output_prefix: str | None = None,
40494042
page_range: str | Sequence[str] | None = None,
40504043
resolution: int = 300,
4051-
color_model: Literal["rgb", "cmyk", "gray"] = "rgb",
4052-
smoothing: Literal["none", "all", "text", "line", "image"]
4053-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4054-
| None = None,
4044+
color_model: JpegColorModel = "rgb",
4045+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40554046
jpeg_quality: int = 75,
40564047
extra_query: Query | None = None,
40574048
extra_headers: AnyMapping | None = None,
@@ -4090,10 +4081,8 @@ async def convert_to_tiff(
40904081
output_prefix: str | None = None,
40914082
page_range: str | Sequence[str] | None = None,
40924083
resolution: int = 300,
4093-
color_model: Literal["rgb", "rgba", "cmyk", "lab", "gray"] = "rgb",
4094-
smoothing: Literal["none", "all", "text", "line", "image"]
4095-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4096-
| None = None,
4084+
color_model: TiffColorModel = "rgb",
4085+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40974086
extra_query: Query | None = None,
40984087
extra_headers: AnyMapping | None = None,
40994088
extra_body: Body | None = None,

src/pdfrest/types/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
from .public import (
44
ALL_PDF_INFO_QUERIES,
5+
BmpColorModel,
6+
CompressionLevel,
7+
ExtractTextGranularity,
8+
FlattenQuality,
9+
GifColorModel,
10+
GraphicSmoothing,
11+
JpegColorModel,
512
PdfAType,
613
PdfInfoQuery,
714
PdfMergeInput,
@@ -12,14 +19,23 @@
1219
PdfRedactionType,
1320
PdfRGBColor,
1421
PdfXType,
22+
PngColorModel,
1523
SummaryFormat,
1624
SummaryOutputFormat,
1725
SummaryOutputType,
26+
TiffColorModel,
1827
TranslateOutputFormat,
1928
)
2029

2130
__all__ = [
2231
"ALL_PDF_INFO_QUERIES",
32+
"BmpColorModel",
33+
"CompressionLevel",
34+
"ExtractTextGranularity",
35+
"FlattenQuality",
36+
"GifColorModel",
37+
"GraphicSmoothing",
38+
"JpegColorModel",
2339
"PdfAType",
2440
"PdfInfoQuery",
2541
"PdfMergeInput",
@@ -30,8 +46,10 @@
3046
"PdfRedactionPreset",
3147
"PdfRedactionType",
3248
"PdfXType",
49+
"PngColorModel",
3350
"SummaryFormat",
3451
"SummaryOutputFormat",
3552
"SummaryOutputType",
53+
"TiffColorModel",
3654
"TranslateOutputFormat",
3755
]

src/pdfrest/types/public.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
__all__ = (
1616
"ALL_PDF_INFO_QUERIES",
17+
"BmpColorModel",
18+
"CompressionLevel",
19+
"ExtractTextGranularity",
20+
"FlattenQuality",
21+
"GifColorModel",
22+
"GraphicSmoothing",
23+
"JpegColorModel",
1724
"PdfAType",
1825
"PdfInfoQuery",
1926
"PdfMergeInput",
@@ -24,9 +31,11 @@
2431
"PdfRedactionPreset",
2532
"PdfRedactionType",
2633
"PdfXType",
34+
"PngColorModel",
2735
"SummaryFormat",
2836
"SummaryOutputFormat",
2937
"SummaryOutputType",
38+
"TiffColorModel",
3039
"TranslateOutputFormat",
3140
)
3241

@@ -105,6 +114,15 @@ class PdfMergeSource(TypedDict, total=False):
105114

106115
PdfAType = Literal["PDF/A-1b", "PDF/A-2b", "PDF/A-2u", "PDF/A-3b", "PDF/A-3u"]
107116
PdfXType = Literal["PDF/X-1a", "PDF/X-3", "PDF/X-4", "PDF/X-6"]
117+
ExtractTextGranularity = Literal["off", "by_page", "document"]
118+
CompressionLevel = Literal["low", "medium", "high", "custom"]
119+
FlattenQuality = Literal["low", "medium", "high"]
120+
PngColorModel = Literal["rgb", "rgba", "gray"]
121+
BmpColorModel = Literal["rgb", "gray"]
122+
GifColorModel = Literal["rgb", "gray"]
123+
JpegColorModel = Literal["rgb", "cmyk", "gray"]
124+
TiffColorModel = Literal["rgb", "rgba", "cmyk", "lab", "gray"]
125+
GraphicSmoothing = Literal["none", "all", "text", "line", "image"]
108126

109127
SummaryFormat = Literal[
110128
"overview",

0 commit comments

Comments
 (0)