Skip to content

Commit bfa954f

Browse files
Create types for remaining Literal arguments in clients
1 parent ef2da63 commit bfa954f

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,
@@ -2875,10 +2884,8 @@ def convert_to_png(
28752884
output_prefix: str | None = None,
28762885
page_range: str | Sequence[str] | None = None,
28772886
resolution: int = 300,
2878-
color_model: Literal["rgb", "rgba", "gray"] = "rgb",
2879-
smoothing: Literal["none", "all", "text", "line", "image"]
2880-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2881-
| None = None,
2887+
color_model: PngColorModel = "rgb",
2888+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
28822889
extra_query: Query | None = None,
28832890
extra_headers: AnyMapping | None = None,
28842891
extra_body: Body | None = None,
@@ -2915,10 +2922,8 @@ def convert_to_bmp(
29152922
output_prefix: str | None = None,
29162923
page_range: str | Sequence[str] | None = None,
29172924
resolution: int = 300,
2918-
color_model: Literal["rgb", "gray"] = "rgb",
2919-
smoothing: Literal["none", "all", "text", "line", "image"]
2920-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2921-
| None = None,
2925+
color_model: BmpColorModel = "rgb",
2926+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
29222927
extra_query: Query | None = None,
29232928
extra_headers: AnyMapping | None = None,
29242929
extra_body: Body | None = None,
@@ -2955,10 +2960,8 @@ def convert_to_gif(
29552960
output_prefix: str | None = None,
29562961
page_range: str | Sequence[str] | None = None,
29572962
resolution: int = 300,
2958-
color_model: Literal["rgb", "gray"] = "rgb",
2959-
smoothing: Literal["none", "all", "text", "line", "image"]
2960-
| Sequence[Literal["none", "all", "text", "line", "image"]]
2961-
| None = None,
2963+
color_model: GifColorModel = "rgb",
2964+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
29622965
extra_query: Query | None = None,
29632966
extra_headers: AnyMapping | None = None,
29642967
extra_body: Body | None = None,
@@ -2995,10 +2998,8 @@ def convert_to_jpeg(
29952998
output_prefix: str | None = None,
29962999
page_range: str | Sequence[str] | None = None,
29973000
resolution: int = 300,
2998-
color_model: Literal["rgb", "cmyk", "gray"] = "rgb",
2999-
smoothing: Literal["none", "all", "text", "line", "image"]
3000-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3001-
| None = None,
3001+
color_model: JpegColorModel = "rgb",
3002+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
30023003
jpeg_quality: int = 75,
30033004
extra_query: Query | None = None,
30043005
extra_headers: AnyMapping | None = None,
@@ -3037,10 +3038,8 @@ def convert_to_tiff(
30373038
output_prefix: str | None = None,
30383039
page_range: str | Sequence[str] | None = None,
30393040
resolution: int = 300,
3040-
color_model: Literal["rgb", "rgba", "cmyk", "lab", "gray"] = "rgb",
3041-
smoothing: Literal["none", "all", "text", "line", "image"]
3042-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3043-
| None = None,
3041+
color_model: TiffColorModel = "rgb",
3042+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
30443043
extra_query: Query | None = None,
30453044
extra_headers: AnyMapping | None = None,
30463045
extra_body: Body | None = None,
@@ -3400,7 +3399,7 @@ async def extract_pdf_text_to_file(
34003399
file: PdfRestFile | Sequence[PdfRestFile],
34013400
*,
34023401
pages: PdfPageSelection | None = None,
3403-
full_text: Literal["off", "by_page", "document"] = "document",
3402+
full_text: ExtractTextGranularity = "document",
34043403
preserve_line_breaks: bool = False,
34053404
word_style: bool = False,
34063405
word_coordinates: bool = False,
@@ -3727,7 +3726,7 @@ async def compress_pdf(
37273726
self,
37283727
file: PdfRestFile | Sequence[PdfRestFile],
37293728
*,
3730-
compression_level: Literal["low", "medium", "high", "custom"],
3729+
compression_level: CompressionLevel,
37313730
profile: PdfRestFile | Sequence[PdfRestFile] | None = None,
37323731
output: str | None = None,
37333732
extra_query: Query | None = None,
@@ -3761,7 +3760,7 @@ async def flatten_transparencies(
37613760
file: PdfRestFile | Sequence[PdfRestFile],
37623761
*,
37633762
output: str | None = None,
3764-
quality: Literal["low", "medium", "high"] = "medium",
3763+
quality: FlattenQuality = "medium",
37653764
extra_query: Query | None = None,
37663765
extra_headers: AnyMapping | None = None,
37673766
extra_body: Body | None = None,
@@ -3925,10 +3924,8 @@ async def convert_to_png(
39253924
output_prefix: str | None = None,
39263925
page_range: str | Sequence[str] | None = None,
39273926
resolution: int = 300,
3928-
color_model: Literal["rgb", "rgba", "gray"] = "rgb",
3929-
smoothing: Literal["none", "all", "text", "line", "image"]
3930-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3931-
| None = None,
3927+
color_model: PngColorModel = "rgb",
3928+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
39323929
extra_query: Query | None = None,
39333930
extra_headers: AnyMapping | None = None,
39343931
extra_body: Body | None = None,
@@ -3965,10 +3962,8 @@ async def convert_to_bmp(
39653962
output_prefix: str | None = None,
39663963
page_range: str | Sequence[str] | None = None,
39673964
resolution: int = 300,
3968-
color_model: Literal["rgb", "gray"] = "rgb",
3969-
smoothing: Literal["none", "all", "text", "line", "image"]
3970-
| Sequence[Literal["none", "all", "text", "line", "image"]]
3971-
| None = None,
3965+
color_model: BmpColorModel = "rgb",
3966+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
39723967
extra_query: Query | None = None,
39733968
extra_headers: AnyMapping | None = None,
39743969
extra_body: Body | None = None,
@@ -4005,10 +4000,8 @@ async def convert_to_gif(
40054000
output_prefix: str | None = None,
40064001
page_range: str | Sequence[str] | None = None,
40074002
resolution: int = 300,
4008-
color_model: Literal["rgb", "gray"] = "rgb",
4009-
smoothing: Literal["none", "all", "text", "line", "image"]
4010-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4011-
| None = None,
4003+
color_model: GifColorModel = "rgb",
4004+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40124005
extra_query: Query | None = None,
40134006
extra_headers: AnyMapping | None = None,
40144007
extra_body: Body | None = None,
@@ -4045,10 +4038,8 @@ async def convert_to_jpeg(
40454038
output_prefix: str | None = None,
40464039
page_range: str | Sequence[str] | None = None,
40474040
resolution: int = 300,
4048-
color_model: Literal["rgb", "cmyk", "gray"] = "rgb",
4049-
smoothing: Literal["none", "all", "text", "line", "image"]
4050-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4051-
| None = None,
4041+
color_model: JpegColorModel = "rgb",
4042+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40524043
jpeg_quality: int = 75,
40534044
extra_query: Query | None = None,
40544045
extra_headers: AnyMapping | None = None,
@@ -4087,10 +4078,8 @@ async def convert_to_tiff(
40874078
output_prefix: str | None = None,
40884079
page_range: str | Sequence[str] | None = None,
40894080
resolution: int = 300,
4090-
color_model: Literal["rgb", "rgba", "cmyk", "lab", "gray"] = "rgb",
4091-
smoothing: Literal["none", "all", "text", "line", "image"]
4092-
| Sequence[Literal["none", "all", "text", "line", "image"]]
4093-
| None = None,
4081+
color_model: TiffColorModel = "rgb",
4082+
smoothing: GraphicSmoothing | Sequence[GraphicSmoothing] | None = None,
40944083
extra_query: Query | None = None,
40954084
extra_headers: AnyMapping | None = None,
40964085
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)