imgproxykit 0.5.0__tar.gz → 0.6.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.
Files changed (79) hide show
  1. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/PKG-INFO +25 -9
  2. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/README.md +22 -8
  3. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/client.py +3 -8
  4. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/settings.py +6 -2
  5. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/shortcuts.py +28 -11
  6. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/drf/serializers.py +10 -4
  7. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/fastapi/dependencies.py +1 -1
  8. imgproxykit-0.6.0/imgproxykit/integrations/litestar/__init__.py +13 -0
  9. imgproxykit-0.6.0/imgproxykit/integrations/litestar/plugin.py +93 -0
  10. imgproxykit-0.6.0/imgproxykit/internal/types.py +9 -0
  11. imgproxykit-0.6.0/imgproxykit/keyword_options.py +92 -0
  12. imgproxykit-0.6.0/imgproxykit/options/base.py +68 -0
  13. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/preset.py +0 -1
  14. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/transform.py +17 -48
  15. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/pyproject.toml +12 -3
  16. imgproxykit-0.5.0/imgproxykit/options/base.py +0 -134
  17. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/LICENSE +0 -0
  18. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/__init__.py +0 -0
  19. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/__init__.py +0 -0
  20. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/__init__.py +0 -0
  21. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/apps.py +0 -0
  22. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/client.py +0 -0
  23. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/sources.py +0 -0
  24. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/templatetags/__init__.py +0 -0
  25. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/django/templatetags/imgproxykit.py +0 -0
  26. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/drf/__init__.py +0 -0
  27. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/integrations/fastapi/__init__.py +0 -0
  28. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/internal/__init__.py +0 -0
  29. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/internal/encoding.py +0 -0
  30. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/__init__.py +0 -0
  31. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/auto_rotate.py +0 -0
  32. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/background.py +0 -0
  33. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/blur.py +0 -0
  34. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/cache_buster.py +0 -0
  35. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/crop.py +0 -0
  36. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/dpr.py +0 -0
  37. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/enforce_thumbnail.py +0 -0
  38. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/enlarge.py +0 -0
  39. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/expires.py +0 -0
  40. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/extend.py +0 -0
  41. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/extend_aspect_ratio.py +0 -0
  42. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/filename.py +0 -0
  43. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/flip.py +0 -0
  44. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/format.py +0 -0
  45. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/format_quality.py +0 -0
  46. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/gravity.py +0 -0
  47. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/height.py +0 -0
  48. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/keep_copyright.py +0 -0
  49. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_animation_frame_resolution.py +0 -0
  50. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_animation_frames.py +0 -0
  51. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_bytes.py +0 -0
  52. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_result_dimension.py +0 -0
  53. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_src_file_size.py +0 -0
  54. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/max_src_resolution.py +0 -0
  55. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/min_height.py +0 -0
  56. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/min_width.py +0 -0
  57. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/padding.py +0 -0
  58. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/pixelate.py +0 -0
  59. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/preserve_hdr.py +0 -0
  60. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/quality.py +0 -0
  61. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/raw.py +0 -0
  62. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/resize.py +0 -0
  63. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/resizing_type.py +0 -0
  64. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/return_attachment.py +0 -0
  65. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/rotate.py +0 -0
  66. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/sharpen.py +0 -0
  67. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/size.py +0 -0
  68. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/skip_processing.py +0 -0
  69. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/strip_color_profile.py +0 -0
  70. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/strip_metadata.py +0 -0
  71. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/trim.py +0 -0
  72. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/watermark.py +0 -0
  73. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/width.py +0 -0
  74. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/options/zoom.py +0 -0
  75. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/py.typed +0 -0
  76. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/serialization.py +0 -0
  77. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/signing.py +0 -0
  78. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/types.py +0 -0
  79. {imgproxykit-0.5.0 → imgproxykit-0.6.0}/imgproxykit/variants.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: imgproxykit
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: A typed Python toolkit for building imgproxy URLs
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -23,10 +23,12 @@ Classifier: Typing :: Typed
23
23
  Provides-Extra: django
24
24
  Provides-Extra: drf
25
25
  Provides-Extra: fastapi
26
+ Provides-Extra: litestar
26
27
  Requires-Dist: django (>=5.2,<7) ; extra == "django"
27
28
  Requires-Dist: django (>=5.2,<7) ; extra == "drf"
28
29
  Requires-Dist: djangorestframework (>=3.16,<4) ; extra == "drf"
29
30
  Requires-Dist: fastapi (>=0.135.2,<1) ; extra == "fastapi"
31
+ Requires-Dist: litestar (>=2.24,<3) ; extra == "litestar"
30
32
  Requires-Dist: typing-extensions (>=4.16,<5)
31
33
  Project-URL: Changelog, https://github.com/kondratevdev/imgproxykit/releases
32
34
  Project-URL: Documentation, https://imgproxykit.readthedocs.io/en/latest/
@@ -50,6 +52,10 @@ Description-Content-Type: text/markdown
50
52
 
51
53
  </div>
52
54
 
55
+ > Build [imgproxy](https://imgproxy.net/) URLs with typed Python options and
56
+ > reusable transformations. Define image settings once, compose them for
57
+ > different use cases, and generate named variants from a single source.
58
+
53
59
  ## Features
54
60
 
55
61
  - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
@@ -57,7 +63,7 @@ Description-Content-Type: text/markdown
57
63
  - [x] Immutable, reusable transforms combining typed options and scalar arguments
58
64
  - [x] Variants: generate multiple image URLs from a reusable set of transforms
59
65
  - [x] Support for named presets configured on your `imgproxy` server
60
- - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
66
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI`, `Litestar` integration
61
67
 
62
68
  ---------
63
69
 
@@ -73,15 +79,17 @@ pip install imgproxykit
73
79
  There are several included extras:
74
80
 
75
81
  - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
76
- with settings, shortcuts, and template tags
82
+ with shortcuts, template tags, and client configuration through Django settings
77
83
  - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
78
84
  with serializer fields for image URLs and named variants
79
85
  - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
80
- with client registration and dependency injection
86
+ with a dependency for injecting the client into route handlers
87
+ - `'imgproxykit[litestar]'` provides [Litestar integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/litestar.html)
88
+ with a plugin that injects the client into route handlers
81
89
 
82
90
  ## Examples
83
91
 
84
- ### Single URL
92
+ ### Generate a thumbnail URL
85
93
 
86
94
  Build a URL for a cropped `webp` thumbnail:
87
95
 
@@ -103,7 +111,7 @@ Build a URL for a cropped `webp` thumbnail:
103
111
 
104
112
  ```
105
113
 
106
- The generated URL has this structure, with the source URL encoded as URL-safe Base64:
114
+ The generated URL has this structure, with the source URL encoded as URL-safe `base64`:
107
115
 
108
116
  ```text
109
117
  https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
@@ -111,7 +119,7 @@ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<
111
119
 
112
120
  `thumbnail_url` points to a cropped `webp` thumbnail.
113
121
 
114
- ### Variants
122
+ ### Generate image variants
115
123
 
116
124
  Build variants by extending a shared transform with a width for each size:
117
125
 
@@ -135,8 +143,16 @@ Build variants by extending a shared transform with a width for each size:
135
143
 
136
144
  ```
137
145
 
138
- `product_urls` contains a URL for each size, all using the shared quality
139
- and WebP format.
146
+ `product_urls` maps each variant name to its generated URL
147
+ (shown here with the encoded source abbreviated):
148
+
149
+ ```text
150
+ {
151
+ 'small': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:320/<encoded-source>',
152
+ 'medium': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:640/<encoded-source>',
153
+ 'large': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:1280/<encoded-source>',
154
+ }
155
+ ```
140
156
 
141
157
  ## Next steps
142
158
 
@@ -14,6 +14,10 @@
14
14
 
15
15
  </div>
16
16
 
17
+ > Build [imgproxy](https://imgproxy.net/) URLs with typed Python options and
18
+ > reusable transformations. Define image settings once, compose them for
19
+ > different use cases, and generate named variants from a single source.
20
+
17
21
  ## Features
18
22
 
19
23
  - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
@@ -21,7 +25,7 @@
21
25
  - [x] Immutable, reusable transforms combining typed options and scalar arguments
22
26
  - [x] Variants: generate multiple image URLs from a reusable set of transforms
23
27
  - [x] Support for named presets configured on your `imgproxy` server
24
- - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
28
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI`, `Litestar` integration
25
29
 
26
30
  ---------
27
31
 
@@ -37,15 +41,17 @@ pip install imgproxykit
37
41
  There are several included extras:
38
42
 
39
43
  - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
40
- with settings, shortcuts, and template tags
44
+ with shortcuts, template tags, and client configuration through Django settings
41
45
  - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
42
46
  with serializer fields for image URLs and named variants
43
47
  - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
44
- with client registration and dependency injection
48
+ with a dependency for injecting the client into route handlers
49
+ - `'imgproxykit[litestar]'` provides [Litestar integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/litestar.html)
50
+ with a plugin that injects the client into route handlers
45
51
 
46
52
  ## Examples
47
53
 
48
- ### Single URL
54
+ ### Generate a thumbnail URL
49
55
 
50
56
  Build a URL for a cropped `webp` thumbnail:
51
57
 
@@ -67,7 +73,7 @@ Build a URL for a cropped `webp` thumbnail:
67
73
 
68
74
  ```
69
75
 
70
- The generated URL has this structure, with the source URL encoded as URL-safe Base64:
76
+ The generated URL has this structure, with the source URL encoded as URL-safe `base64`:
71
77
 
72
78
  ```text
73
79
  https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
@@ -75,7 +81,7 @@ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<
75
81
 
76
82
  `thumbnail_url` points to a cropped `webp` thumbnail.
77
83
 
78
- ### Variants
84
+ ### Generate image variants
79
85
 
80
86
  Build variants by extending a shared transform with a width for each size:
81
87
 
@@ -99,8 +105,16 @@ Build variants by extending a shared transform with a width for each size:
99
105
 
100
106
  ```
101
107
 
102
- `product_urls` contains a URL for each size, all using the shared quality
103
- and WebP format.
108
+ `product_urls` maps each variant name to its generated URL
109
+ (shown here with the encoded source abbreviated):
110
+
111
+ ```text
112
+ {
113
+ 'small': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:320/<encoded-source>',
114
+ 'medium': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:640/<encoded-source>',
115
+ 'large': 'https://imgproxy.example.com/unsafe/quality:85/format:webp/width:1280/<encoded-source>',
116
+ }
117
+ ```
104
118
 
105
119
  ## Next steps
106
120
 
@@ -1,6 +1,7 @@
1
1
  from collections.abc import Mapping
2
2
  from typing import TYPE_CHECKING, ClassVar, overload
3
3
 
4
+ from imgproxykit.internal.types import VariantsResult
4
5
  from imgproxykit.serialization import PathSerializer
5
6
  from imgproxykit.signing import UrlSigner
6
7
  from imgproxykit.transform import Transform
@@ -10,10 +11,6 @@ from imgproxykit.variants import DataclassVariantsResolver
10
11
  if TYPE_CHECKING:
11
12
  from _typeshed import DataclassInstance
12
13
 
13
- type _VariantsResult[Key: str] = (
14
- dict[Key, str] | dict[str, str] | DataclassInstance
15
- )
16
-
17
14
 
18
15
  class Client:
19
16
  """
@@ -182,8 +179,7 @@ class Client:
182
179
 
183
180
  Returns:
184
181
  The complete imgproxy URL, signed when credentials were supplied
185
- or containing the unsigned marker otherwise. No network request
186
- is made.
182
+ or containing the unsigned marker otherwise.
187
183
  """
188
184
  path = self._path_serializer(source, transform=transform)
189
185
  signature = self._url_signer(path)
@@ -210,7 +206,7 @@ class Client:
210
206
  source: str,
211
207
  *,
212
208
  variants: Mapping[Key, Transform] | type['DataclassInstance'],
213
- ) -> _VariantsResult[Key]:
209
+ ) -> VariantsResult[Key]:
214
210
  """
215
211
  Build named URLs for one source using complete transformations.
216
212
 
@@ -227,7 +223,6 @@ class Client:
227
223
  An empty mapping produces an empty dictionary.
228
224
  A dataclass class produces a new instance of that exact class,
229
225
  with a generated URL in every field.
230
- No network request is made.
231
226
  """
232
227
  transforms = (
233
228
  variants
@@ -1,6 +1,6 @@
1
1
  import enum
2
2
  from collections.abc import Callable, Mapping
3
- from typing import Any, Final, Required, final
3
+ from typing import TYPE_CHECKING, Any, Final, Required, final
4
4
 
5
5
  from django.core.exceptions import ImproperlyConfigured
6
6
  from django.db.models.fields.files import FieldFile
@@ -9,6 +9,10 @@ from typing_extensions import TypedDict
9
9
  from imgproxykit.transform import Transform
10
10
  from imgproxykit.types import SourceEncoding
11
11
 
12
+ if TYPE_CHECKING:
13
+ from _typeshed import DataclassInstance
14
+
15
+
12
16
  #: Django setting containing the imgproxy client configuration.
13
17
  IMGPROXYKIT_SETTINGS: Final = 'IMGPROXYKIT'
14
18
 
@@ -68,7 +72,7 @@ class SettingsDict(TypedDict, total=False, closed=True):
68
72
  #: Named Python transformations, distinct from imgproxy server presets.
69
73
  transforms: Mapping[str, Transform]
70
74
  #: Named sets of transformations; objects can be shared with transforms.
71
- variants: Mapping[str, Mapping[str, Transform]]
75
+ variants: Mapping[str, Mapping[str, Transform] | type['DataclassInstance']]
72
76
  #: Convert the original source to a URI, including empty file fields.
73
77
  source_resolver: Callable[[str | FieldFile], str] | str
74
78
 
@@ -1,13 +1,18 @@
1
1
  from collections.abc import Mapping
2
- from typing import overload
2
+ from dataclasses import asdict, is_dataclass
3
+ from typing import TYPE_CHECKING, overload
3
4
 
4
5
  from django.db.models.fields.files import FieldFile
5
6
 
6
7
  from imgproxykit.integrations.django.client import get_client
7
8
  from imgproxykit.integrations.django.settings import Settings, get_config
8
9
  from imgproxykit.integrations.django.sources import resolve_source
10
+ from imgproxykit.internal.types import VariantsResult
9
11
  from imgproxykit.transform import Transform
10
12
 
13
+ if TYPE_CHECKING:
14
+ from _typeshed import DataclassInstance
15
+
11
16
 
12
17
  def imgproxy_url(
13
18
  source: str | FieldFile,
@@ -33,6 +38,13 @@ def imgproxy_url(
33
38
  return get_client().url(resolve_source(source), transform=transform)
34
39
 
35
40
 
41
+ @overload
42
+ def imgproxy_variants(
43
+ source: str | FieldFile,
44
+ variants: str,
45
+ ) -> dict[str, str]: ...
46
+
47
+
36
48
  @overload
37
49
  def imgproxy_variants[Key: str](
38
50
  source: str | FieldFile,
@@ -41,26 +53,28 @@ def imgproxy_variants[Key: str](
41
53
 
42
54
 
43
55
  @overload
44
- def imgproxy_variants(
56
+ def imgproxy_variants[VariantSet: DataclassInstance](
45
57
  source: str | FieldFile,
46
- variants: str,
47
- ) -> dict[str, str]: ...
58
+ variants: type[VariantSet],
59
+ ) -> VariantSet: ...
48
60
 
49
61
 
50
62
  def imgproxy_variants[Key: str](
51
63
  source: str | FieldFile,
52
- variants: Mapping[Key, Transform] | str,
53
- ) -> dict[Key, str] | dict[str, str]:
64
+ variants: Mapping[Key, Transform] | type['DataclassInstance'] | str,
65
+ ) -> VariantsResult[Key]:
54
66
  """
55
67
  Build named image URLs using Django's configured client.
56
68
 
57
69
  Args:
58
70
  source: Source URI or model file field, resolved once for all variants.
59
- variants: Transformation mapping or set name from
60
- ``IMGPROXYKIT['variants']``.
71
+ variants: Transformation mapping, dataclass class,
72
+ or set name from ``IMGPROXYKIT['variants']``.
61
73
 
62
74
  Returns:
63
75
  URLs in variant order. Direct mappings preserve their key type.
76
+ Dataclass classes passed directly produce instances of that class.
77
+ Named sets always produce dictionaries of URLs.
64
78
 
65
79
  Raises:
66
80
  KeyError: If a named variant set is not configured.
@@ -68,10 +82,13 @@ def imgproxy_variants[Key: str](
68
82
  """
69
83
  client = get_client()
70
84
 
71
- # Resolve the source inside each branch so named sets are looked up first.
72
- # Only one branch runs, so the resolver is called once per invocation.
85
+ # 1. For a mapping or dataclass class, return the client result as is.
86
+ # 2. For a set name, read its declaration from settings first.
87
+ # 3. Resolve the source once, then build the URLs.
88
+ # 4. Always return a dict for a set name, even if it uses a dataclass.
73
89
  if not isinstance(variants, str):
74
90
  return client.variants(resolve_source(source), variants=variants)
75
91
 
76
92
  configured = get_config()[Settings.variants.value][variants] # pyright: ignore[reportTypedDictNotRequiredAccess]
77
- return client.variants(resolve_source(source), variants=configured)
93
+ images = client.variants(resolve_source(source), variants=configured)
94
+ return asdict(images) if is_dataclass(images) else images
@@ -1,5 +1,6 @@
1
1
  from collections.abc import Mapping
2
- from typing import Any, override
2
+ from dataclasses import asdict, is_dataclass
3
+ from typing import TYPE_CHECKING, Any, override
3
4
 
4
5
  from django.db.models.fields.files import FieldFile
5
6
  from rest_framework import serializers
@@ -7,6 +8,9 @@ from rest_framework import serializers
7
8
  from imgproxykit.integrations.django import imgproxy_url, imgproxy_variants
8
9
  from imgproxykit.transform import Transform
9
10
 
11
+ if TYPE_CHECKING:
12
+ from _typeshed import DataclassInstance
13
+
10
14
 
11
15
  class ImgproxyURLField(serializers.URLField):
12
16
  """
@@ -66,9 +70,10 @@ class ImgproxyVariantsField(serializers.DictField):
66
70
  all variants. Empty sources return ``None`` without calling the resolver.
67
71
  ``read_only`` must be ``True`` and ``write_only`` must be ``False``.
68
72
  ``child`` cannot be supplied; variant values always use a URL field.
73
+ Dataclass results are converted to dictionaries of URLs.
69
74
 
70
75
  Args:
71
- variants: Transformation mapping or set name from
76
+ variants: Transformation mapping, dataclass class, or set name from
72
77
  ``IMGPROXYKIT['variants']``.
73
78
  **kwargs: DRF field options. ``allow_null`` defaults to ``True``.
74
79
  """
@@ -76,7 +81,7 @@ class ImgproxyVariantsField(serializers.DictField):
76
81
  def __init__(
77
82
  self,
78
83
  *,
79
- variants: Mapping[str, Transform] | str,
84
+ variants: Mapping[str, Transform] | type['DataclassInstance'] | str,
80
85
  **kwargs: Any,
81
86
  ) -> None:
82
87
  """Configure the variants and DRF field options."""
@@ -114,4 +119,5 @@ class ImgproxyVariantsField(serializers.DictField):
114
119
  if not value:
115
120
  return None
116
121
 
117
- return imgproxy_variants(value, self.variants)
122
+ images = imgproxy_variants(value, self.variants)
123
+ return asdict(images) if is_dataclass(images) else images
@@ -27,7 +27,7 @@ def add_imgproxy(
27
27
 
28
28
  Returns:
29
29
  An async dependency returning the registered client. URL generation
30
- remains synchronous and makes no network requests.
30
+ remains synchronous.
31
31
 
32
32
  Raises:
33
33
  ValueError: If the application's state already has this attribute.
@@ -0,0 +1,13 @@
1
+ # Optional integrations check their dependencies before importing adapters.
2
+ # flake8: noqa: WPS412
3
+ try: # noqa: RUF067
4
+ import litestar # noqa: F401 # pyright: ignore[reportUnusedImport]
5
+ except ImportError as exc: # pragma: no cover
6
+ raise ImportError(
7
+ 'The Litestar integration requires Litestar. '
8
+ "Install it with `pip install 'imgproxykit[litestar]'`.",
9
+ ) from exc
10
+
11
+ from imgproxykit.integrations.litestar.plugin import (
12
+ ImgproxyPlugin as ImgproxyPlugin,
13
+ )
@@ -0,0 +1,93 @@
1
+ from collections.abc import Mapping
2
+ from typing import overload, override
3
+
4
+ from litestar.config.app import AppConfig
5
+ from litestar.di import Provide
6
+ from litestar.plugins import InitPlugin
7
+
8
+ from imgproxykit.client import Client
9
+
10
+
11
+ class ImgproxyPlugin(InitPlugin):
12
+ """
13
+ Register imgproxy clients as Litestar dependencies.
14
+
15
+ Pass one client positionally to register it as ``'imgproxy'``, or supply
16
+ a mapping of dependency names to clients through ``clients``. Add the
17
+ plugin to ``Litestar(plugins=[...])`` when creating the application.
18
+
19
+ Clients are reused across requests. Handler parameters must use
20
+ ``NamedDependency[Client]`` and match the registered dependency names.
21
+ """
22
+
23
+ __slots__ = ('_clients',)
24
+
25
+ @overload
26
+ def __init__(self, client: Client, /) -> None: ...
27
+
28
+ @overload
29
+ def __init__(self, /, *, clients: Mapping[str, Client]) -> None: ...
30
+
31
+ def __init__(
32
+ self,
33
+ client: Client | None = None,
34
+ /,
35
+ *,
36
+ clients: Mapping[str, Client] | None = None,
37
+ ) -> None:
38
+ """
39
+ Configure the clients to register during application initialization.
40
+
41
+ Args:
42
+ client: Client registered under the default name ``'imgproxy'``.
43
+ Supply positionally, without ``clients``.
44
+ clients: Dependency names mapped to configured clients. Copied
45
+ during initialization. Supply without ``client``.
46
+
47
+ Raises:
48
+ TypeError: If both arguments are supplied or neither is supplied.
49
+ """
50
+ if client is not None and clients is not None:
51
+ raise TypeError('Pass either client or clients, not both.')
52
+ if client is not None:
53
+ self._clients = {'imgproxy': client}
54
+ elif clients is not None:
55
+ self._clients = dict(clients)
56
+ else:
57
+ raise TypeError('Pass client or clients.')
58
+
59
+ @override
60
+ def on_app_init(self, app_config: AppConfig) -> AppConfig:
61
+ """
62
+ Register the configured clients as application dependencies.
63
+
64
+ Args:
65
+ app_config: Litestar configuration to update before startup.
66
+
67
+ Returns:
68
+ The supplied configuration with client dependencies registered.
69
+
70
+ Raises:
71
+ ValueError: If a dependency name is already registered. Existing
72
+ dependencies are checked before adding any client providers.
73
+ """
74
+ for dependency_key in self._clients:
75
+ if dependency_key in app_config.dependencies:
76
+ raise ValueError(
77
+ 'Application dependencies already contain '
78
+ f'{dependency_key!r}.',
79
+ )
80
+
81
+ app_config.dependencies.update({
82
+ name: self._create_provider(client)
83
+ for name, client in self._clients.items()
84
+ })
85
+ return app_config
86
+
87
+ def _create_provider(self, client: Client) -> Provide:
88
+ """Bind one client to a provider without injectable parameters."""
89
+
90
+ def get_client() -> Client: # noqa: WPS430
91
+ return client
92
+
93
+ return Provide(get_client, sync_to_thread=False)
@@ -0,0 +1,9 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ if TYPE_CHECKING:
4
+ from _typeshed import DataclassInstance
5
+
6
+ type VariantsResult[Key: str] = (
7
+ dict[Key, str] | dict[str, str] | DataclassInstance
8
+ )
9
+ """Result types shared by variant method implementations and shortcuts."""
@@ -0,0 +1,92 @@
1
+ from typing import Annotated, Any, ClassVar, get_args, get_type_hints
2
+
3
+ from typing_extensions import TypedDict
4
+
5
+ from imgproxykit import options
6
+ from imgproxykit.types import Argument, FormatType, ResizeType
7
+
8
+ type _ScalarOptionClass = type[options.ScalarOption[Any]]
9
+
10
+
11
+ def _resolve_classes() -> dict[str, _ScalarOptionClass]:
12
+ hints = get_type_hints(KeywordOptions, include_extras=True)
13
+ classes = {}
14
+ for keyword, annotation in hints.items():
15
+ _, option_cls = get_args(annotation)
16
+ classes[keyword] = option_cls
17
+ return classes # pyright: ignore[reportUnknownVariableType]
18
+
19
+
20
+ class KeywordOptions(TypedDict, total=False, closed=True):
21
+ """
22
+ Built-in scalar keyword arguments for :class:`~imgproxykit.Transform`.
23
+
24
+ All keywords are optional and are also accepted by
25
+ :meth:`~imgproxykit.Transform.extend`. Each field declares the value type
26
+ and carries the corresponding option class in its ``Annotated`` metadata.
27
+
28
+ The field name is the Python keyword. The option class defines the name
29
+ used in the URL. For example, ``cache_buster="v2"`` creates a
30
+ ``CacheBuster`` option with the URL segment ``cachebuster:v2`` when using
31
+ the default separator and full option names.
32
+
33
+ Pass custom processing options as positional
34
+ :class:`~imgproxykit.options.Option` instances.
35
+ """
36
+
37
+ auto_rotate: Annotated[bool, options.AutoRotate]
38
+ blur: Annotated[float, options.Blur]
39
+ cache_buster: Annotated[str, options.CacheBuster]
40
+ dpr: Annotated[float, options.DPR]
41
+ enforce_thumbnail: Annotated[bool, options.EnforceThumbnail]
42
+ enlarge: Annotated[bool, options.Enlarge]
43
+ expires: Annotated[int, options.Expires]
44
+ filename: Annotated[str, options.Filename]
45
+ format: Annotated[FormatType, options.Format]
46
+ height: Annotated[int, options.Height]
47
+ keep_copyright: Annotated[bool, options.KeepCopyright]
48
+ max_animation_frame_resolution: Annotated[
49
+ float,
50
+ options.MaxAnimationFrameResolution,
51
+ ]
52
+ max_animation_frames: Annotated[int, options.MaxAnimationFrames]
53
+ max_bytes: Annotated[int, options.MaxBytes]
54
+ max_result_dimension: Annotated[int, options.MaxResultDimension]
55
+ max_src_file_size: Annotated[int, options.MaxSrcFileSize]
56
+ max_src_resolution: Annotated[float, options.MaxSrcResolution]
57
+ min_height: Annotated[int, options.MinHeight]
58
+ min_width: Annotated[int, options.MinWidth]
59
+ pixelate: Annotated[int, options.Pixelate]
60
+ preserve_hdr: Annotated[bool, options.PreserveHDR]
61
+ quality: Annotated[int, options.Quality]
62
+ raw: Annotated[bool, options.Raw]
63
+ resizing_type: Annotated[ResizeType, options.ResizingType]
64
+ return_attachment: Annotated[bool, options.ReturnAttachment]
65
+ rotate: Annotated[int, options.Rotate]
66
+ sharpen: Annotated[float, options.Sharpen]
67
+ strip_color_profile: Annotated[bool, options.StripColorProfile]
68
+ strip_metadata: Annotated[bool, options.StripMetadata]
69
+ width: Annotated[int, options.Width]
70
+
71
+
72
+ class KeywordOptionResolver:
73
+ """Resolve built-in scalar options from Transform keywords."""
74
+
75
+ __slots__ = ()
76
+
77
+ _classes: ClassVar[dict[str, _ScalarOptionClass]] = _resolve_classes()
78
+
79
+ @classmethod
80
+ def from_kwarg(
81
+ cls,
82
+ keyword: str,
83
+ value: Argument,
84
+ ) -> options.ScalarOption[Any]:
85
+ """Construct a built-in option from a Transform keyword."""
86
+ option_cls = cls._classes.get(keyword)
87
+ if option_cls is None:
88
+ raise TypeError(
89
+ f'Unknown scalar processing option {keyword!r}. '
90
+ 'Pass custom options as positional arguments.',
91
+ )
92
+ return option_cls(value)
@@ -0,0 +1,68 @@
1
+ from abc import ABC, abstractmethod
2
+ from dataclasses import dataclass
3
+ from typing import ClassVar, override
4
+
5
+ from imgproxykit.types import Argument
6
+
7
+
8
+ class Option(ABC):
9
+ """
10
+ Base class for typed imgproxy processing options.
11
+
12
+ Concrete options provide a fixed name and positional arguments.
13
+ Pass their instances to :class:`~imgproxykit.Transform`.
14
+ This abstract class cannot be instantiated directly.
15
+
16
+ Arguments retain ``None`` values until
17
+ serialization: internal gaps keep their positions, while trailing
18
+ ``None`` values are omitted. Other false values (such as empty
19
+ strings, zeroes, and ``False``) keep their positions.
20
+
21
+ See `imgproxy processing options
22
+ <https://docs.imgproxy.net/usage/processing#processing-options>`_.
23
+ """
24
+
25
+ __slots__ = ()
26
+
27
+ # Public API:
28
+ name: ClassVar[str]
29
+ """
30
+ All subtypes must provide a supported imgproxy processing option name.
31
+
32
+ The name is shared by all instances and is not a dataclass field
33
+ or a constructor argument.
34
+ """
35
+
36
+ short_name: ClassVar[str | None] = None
37
+ """
38
+ Shortest documented imgproxy alias, or ``None`` if none is available.
39
+
40
+ Like ``name``, this is shared by instances and is not a constructor
41
+ argument. Use ``name`` when no short alias is defined.
42
+ """
43
+
44
+ @property
45
+ @abstractmethod
46
+ def arguments(self) -> tuple[Argument, ...]:
47
+ """Positional arguments in imgproxy protocol order."""
48
+
49
+
50
+ @dataclass(frozen=True, slots=True)
51
+ class ScalarOption[ValueT: Argument](Option):
52
+ """
53
+ Base class for processing options accepting one scalar value.
54
+
55
+ Concrete subclasses specify the value type and processing option name.
56
+ Override :attr:`arguments` when the option requires custom encoding.
57
+
58
+ Attributes:
59
+ value: Scalar processing option value.
60
+ """
61
+
62
+ value: ValueT
63
+
64
+ @property
65
+ @override
66
+ def arguments(self) -> tuple[Argument, ...]:
67
+ """Positional arguments in imgproxy protocol order."""
68
+ return (self.value,)
@@ -51,7 +51,6 @@ class Preset(Option):
51
51
  # Keep variadic names while initializing a frozen dataclass.
52
52
  # Bypassing __setattr__ is safe until initialization is finished.
53
53
  object.__setattr__(self, 'names', names)
54
- self.validate()
55
54
 
56
55
  @property
57
56
  @override
@@ -1,50 +1,9 @@
1
1
  from dataclasses import dataclass
2
2
  from itertools import starmap
3
- from typing import Unpack
3
+ from typing import ClassVar, Unpack
4
4
 
5
- from typing_extensions import TypedDict
6
-
7
- from imgproxykit.options import Option, ScalarOption
8
- from imgproxykit.types import FormatType, ResizeType
9
-
10
-
11
- class ScalarOptions(TypedDict, total=False, closed=True):
12
- """
13
- Optional scalar processing arguments.
14
-
15
- Accepted by :class:`Transform` and :meth:`~imgproxykit.Transform.extend`.
16
- """
17
-
18
- auto_rotate: bool
19
- blur: float
20
- cachebuster: str
21
- dpr: float
22
- enforce_thumbnail: bool
23
- enlarge: bool
24
- expires: int
25
- filename: str
26
- format: FormatType
27
- height: int
28
- keep_copyright: bool
29
- max_animation_frame_resolution: float
30
- max_animation_frames: int
31
- max_bytes: int
32
- max_result_dimension: int
33
- max_src_file_size: int
34
- max_src_resolution: float
35
- min_height: int
36
- min_width: int
37
- pixelate: int
38
- preserve_hdr: bool
39
- quality: int
40
- raw: bool
41
- resizing_type: ResizeType
42
- return_attachment: bool
43
- rotate: int
44
- sharpen: float
45
- strip_color_profile: bool
46
- strip_metadata: bool
47
- width: int
5
+ from imgproxykit.keyword_options import KeywordOptionResolver, KeywordOptions
6
+ from imgproxykit.options import Option
48
7
 
49
8
 
50
9
  @dataclass(frozen=True, slots=True, init=False)
@@ -68,12 +27,17 @@ class Transform:
68
27
  which adds no processing option segments to the URL.
69
28
  """
70
29
 
30
+ #: Component that resolves built-in scalar keyword options.
31
+ keyword_option_resolver_cls: ClassVar[type[KeywordOptionResolver]] = (
32
+ KeywordOptionResolver
33
+ )
34
+
71
35
  options: tuple[Option, ...]
72
36
 
73
37
  def __init__(
74
38
  self,
75
39
  *options: Option,
76
- **kwargs: Unpack[ScalarOptions],
40
+ **kwargs: Unpack[KeywordOptions],
77
41
  ) -> None:
78
42
  """
79
43
  Collect positional options, followed by scalar keyword options.
@@ -87,13 +51,18 @@ class Transform:
87
51
  """
88
52
  # Keep variadic options while initializing a frozen dataclass.
89
53
  # Bypassing __setattr__ is safe until initialization is finished.
90
- scalar_options = tuple(starmap(ScalarOption.from_kwarg, kwargs.items()))
54
+ scalar_options = tuple(
55
+ starmap(
56
+ self.keyword_option_resolver_cls.from_kwarg,
57
+ kwargs.items(),
58
+ ),
59
+ )
91
60
  object.__setattr__(self, 'options', (*options, *scalar_options))
92
61
 
93
62
  def extend(
94
63
  self,
95
64
  *options: Option,
96
- **kwargs: Unpack[ScalarOptions],
65
+ **kwargs: Unpack[KeywordOptions],
97
66
  ) -> 'Transform':
98
67
  """
99
68
  Return a new transformation with additional processing options.
@@ -109,4 +78,4 @@ class Transform:
109
78
  or ``format='webp'``. Converted to option instances and
110
79
  appended in keyword order.
111
80
  """
112
- return Transform(*self.options, *options, **kwargs)
81
+ return type(self)(*self.options, *options, **kwargs)
@@ -5,7 +5,7 @@ requires = [ "poetry-core>=2" ]
5
5
 
6
6
  [project]
7
7
  name = "imgproxykit"
8
- version = "0.5.0"
8
+ version = "0.6.0"
9
9
  description = "A typed Python toolkit for building imgproxy URLs"
10
10
  readme = "README.md"
11
11
  keywords = [
@@ -26,6 +26,7 @@ dependencies = [
26
26
  django = [ "django>=5.2,<7" ]
27
27
  drf = [ "django>=5.2,<7", "djangorestframework>=3.16,<4" ]
28
28
  fastapi = [ "fastapi>=0.135.2,<1" ]
29
+ litestar = [ "litestar>=2.24,<3" ]
29
30
 
30
31
  [[project.authors]]
31
32
  name = "Alexander Kondratev"
@@ -62,7 +63,7 @@ mypy = "^2.4"
62
63
  pyrefly = ">=1,<2"
63
64
  pyright = ">=1.1,<2"
64
65
  # TODO: relax the pin after a stable `ty` release:
65
- ty = "==0.0.92"
66
+ ty = "==0.0.95"
66
67
  types-docutils = ">=0.22,<0.24"
67
68
 
68
69
  # Unit tests, snapshots, and coverage:
@@ -78,7 +79,7 @@ time-machine = ">=3.6,<4"
78
79
  # Integration tests and image assertions:
79
80
  pillow = ">=13.0.0,<14"
80
81
  testcontainers = ">=4.15,<5"
81
- zapros = ">=0.23.0,<0.24"
82
+ zapros = ">=0.24.0,<0.25"
82
83
 
83
84
  # Django integration typing and tests:
84
85
  django-modern-rest = { version = ">=0.16,<0.17", extras = [ "pydantic" ] }
@@ -114,6 +115,9 @@ quote-style = "single"
114
115
  docstring-code-format = true
115
116
 
116
117
  [tool.ruff.lint.per-file-ignores]
118
+ # Litestar handlers intentionally run in the event loop without awaiting I/O.
119
+ "test_apps/litestar/*.py" = [ "RUF029" ]
120
+ "docs/examples/integrations/litestar/*.py" = [ "RUF029" ]
117
121
  "tests/*.py" = [
118
122
  "S101", # allow assert statements in tests
119
123
  "SLF001", # allow tests to inspect private members
@@ -310,10 +314,15 @@ addopts = [
310
314
  xfail_strict = true
311
315
  # Fail on warnings:
312
316
  filterwarnings = [ "error" ]
317
+ markers = [
318
+ "imgproxy_env(**env): override imgproxy server env; None removes a default"
319
+ ]
320
+
313
321
  # pytest-asyncio configuration:
314
322
  # https://pytest-asyncio.readthedocs.io/en/stable/reference/configuration.html
315
323
  asyncio_mode = "auto"
316
324
  asyncio_default_fixture_loop_scope = "function"
325
+
317
326
  # Django settings:
318
327
  DJANGO_SETTINGS_MODULE = "server.settings"
319
328
 
@@ -1,134 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from dataclasses import dataclass
3
- from typing import Any, ClassVar, override
4
-
5
- from imgproxykit.types import Argument
6
-
7
-
8
- class Option(ABC):
9
- """
10
- Base class for typed imgproxy processing options.
11
-
12
- Concrete options provide a fixed name and positional arguments.
13
- Pass their instances to :class:`~imgproxykit.Transform`.
14
- This abstract class cannot be instantiated directly.
15
-
16
- Arguments retain ``None`` values until
17
- serialization: internal gaps keep their positions, while trailing
18
- ``None`` values are omitted. Other false values (such as empty
19
- strings, zeroes, and ``False``) keep their positions.
20
-
21
- See `imgproxy processing options
22
- <https://docs.imgproxy.net/usage/processing#processing-options>`_.
23
- """
24
-
25
- __slots__ = ()
26
-
27
- # Public API:
28
- name: ClassVar[str]
29
- """
30
- All subtypes must provide a supported imgproxy processing option name.
31
-
32
- The name is shared by all instances and is not a dataclass field
33
- or a constructor argument.
34
- """
35
-
36
- short_name: ClassVar[str | None] = None
37
- """
38
- Shortest documented imgproxy alias, or ``None`` if none is available.
39
-
40
- Like ``name``, this is shared by instances and is not a constructor
41
- argument. Use ``name`` when no short alias is defined.
42
- """
43
-
44
- def __post_init__(self) -> None:
45
- """Validate option arguments at construction time."""
46
- self.validate()
47
-
48
- def validate(self) -> None: # noqa: B027
49
- """
50
- Validate option arguments.
51
-
52
- Override this method to enforce server-independent constraints.
53
- The default implementation does nothing.
54
-
55
- Raises:
56
- ValueError: If option arguments are invalid.
57
- """
58
- # TODO: Add per option validation
59
-
60
- @property
61
- @abstractmethod
62
- def arguments(self) -> tuple[Argument, ...]:
63
- """Positional arguments in imgproxy protocol order."""
64
-
65
-
66
- type _ScalarRegistry = dict[str, type[ScalarOption[Any]]]
67
-
68
-
69
- @dataclass(frozen=True, slots=True)
70
- class ScalarOption[ValueT: Argument](Option):
71
- """
72
- Base class for processing options accepting one scalar value.
73
-
74
- Subclasses are registered automatically using their processing option
75
- name, with hyphens replaced by underscores. This allows passing scalar
76
- values directly to :class:`~imgproxykit.Transform` as keyword arguments.
77
-
78
- Concrete subclasses specify the value type and processing option name.
79
- Override :attr:`arguments` when the option requires custom encoding.
80
-
81
- Attributes:
82
- value: Scalar processing option value.
83
- """
84
-
85
- value: ValueT
86
-
87
- _registry: ClassVar[_ScalarRegistry] = {}
88
-
89
- @override
90
- def __init_subclass__(cls) -> None:
91
- """Register a concrete scalar option for keyword construction."""
92
- # Explicit super is required because slots=True replaces this class.
93
- super(ScalarOption, cls).__init_subclass__() # noqa: WPS608
94
- # Slotted dataclasses create a replacement class. Register it again
95
- # so keyword construction uses the final class, including its slots.
96
- ScalarOption._registry[cls._get_kwarg_name()] = cls
97
-
98
- @property
99
- @override
100
- def arguments(self) -> tuple[Argument, ...]:
101
- """Positional arguments in imgproxy protocol order."""
102
- return (self.value,)
103
-
104
- @classmethod
105
- def from_kwarg(cls, name: str, value: Argument) -> 'ScalarOption[Any]':
106
- """
107
- Construct a registered scalar option from a Transform keyword.
108
-
109
- The concrete option constructor handles value validation and
110
- protocol-specific encoding, just as with positional options.
111
-
112
- Args:
113
- name: Python keyword name of a registered scalar option.
114
- value: Value passed to the concrete option constructor.
115
-
116
- Raises:
117
- TypeError: If the keyword does not identify a scalar option.
118
- ValueError: If the concrete option rejects the supplied value.
119
- """
120
- option_cls = cls._registry.get(name)
121
- if option_cls is None:
122
- raise TypeError(
123
- f'Unknown scalar processing option {name!r}. '
124
- 'Transform keyword arguments must name a registered scalar '
125
- 'option. '
126
- 'Pass complex processing options as positional Option '
127
- 'instances.',
128
- )
129
- return option_cls(value)
130
-
131
- @classmethod
132
- def _get_kwarg_name(cls) -> str:
133
- """Convert the processing option name to its Python keyword name."""
134
- return cls.name.replace('-', '_')
File without changes