imgproxykit 0.5.0__tar.gz → 0.7.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 (81) hide show
  1. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/PKG-INFO +35 -19
  2. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/README.md +26 -12
  3. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/client.py +14 -12
  4. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/settings.py +20 -15
  5. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/shortcuts.py +28 -11
  6. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/drf/serializers.py +12 -6
  7. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/fastapi/dependencies.py +1 -1
  8. imgproxykit-0.7.0/imgproxykit/integrations/litestar/__init__.py +13 -0
  9. imgproxykit-0.7.0/imgproxykit/integrations/litestar/plugin.py +93 -0
  10. imgproxykit-0.7.0/imgproxykit/internal/types.py +9 -0
  11. imgproxykit-0.7.0/imgproxykit/internal/typing.py +75 -0
  12. imgproxykit-0.7.0/imgproxykit/options/base.py +68 -0
  13. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/preset.py +0 -1
  14. imgproxykit-0.7.0/imgproxykit/serialization.py +297 -0
  15. imgproxykit-0.7.0/imgproxykit/transform.py +175 -0
  16. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/variants.py +4 -4
  17. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/pyproject.toml +31 -20
  18. imgproxykit-0.5.0/imgproxykit/options/base.py +0 -134
  19. imgproxykit-0.5.0/imgproxykit/serialization.py +0 -149
  20. imgproxykit-0.5.0/imgproxykit/transform.py +0 -112
  21. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/LICENSE +0 -0
  22. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/__init__.py +0 -0
  23. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/__init__.py +0 -0
  24. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/__init__.py +0 -0
  25. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/apps.py +0 -0
  26. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/client.py +0 -0
  27. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/sources.py +0 -0
  28. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/templatetags/__init__.py +0 -0
  29. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/django/templatetags/imgproxykit.py +0 -0
  30. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/drf/__init__.py +0 -0
  31. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/integrations/fastapi/__init__.py +0 -0
  32. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/internal/__init__.py +0 -0
  33. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/internal/encoding.py +0 -0
  34. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/__init__.py +0 -0
  35. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/auto_rotate.py +0 -0
  36. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/background.py +0 -0
  37. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/blur.py +0 -0
  38. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/cache_buster.py +0 -0
  39. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/crop.py +0 -0
  40. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/dpr.py +0 -0
  41. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/enforce_thumbnail.py +0 -0
  42. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/enlarge.py +0 -0
  43. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/expires.py +0 -0
  44. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/extend.py +0 -0
  45. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/extend_aspect_ratio.py +0 -0
  46. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/filename.py +0 -0
  47. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/flip.py +0 -0
  48. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/format.py +0 -0
  49. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/format_quality.py +0 -0
  50. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/gravity.py +0 -0
  51. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/height.py +0 -0
  52. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/keep_copyright.py +0 -0
  53. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_animation_frame_resolution.py +0 -0
  54. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_animation_frames.py +0 -0
  55. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_bytes.py +0 -0
  56. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_result_dimension.py +0 -0
  57. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_src_file_size.py +0 -0
  58. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/max_src_resolution.py +0 -0
  59. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/min_height.py +0 -0
  60. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/min_width.py +0 -0
  61. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/padding.py +0 -0
  62. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/pixelate.py +0 -0
  63. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/preserve_hdr.py +0 -0
  64. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/quality.py +0 -0
  65. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/raw.py +0 -0
  66. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/resize.py +0 -0
  67. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/resizing_type.py +0 -0
  68. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/return_attachment.py +0 -0
  69. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/rotate.py +0 -0
  70. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/sharpen.py +0 -0
  71. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/size.py +0 -0
  72. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/skip_processing.py +0 -0
  73. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/strip_color_profile.py +0 -0
  74. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/strip_metadata.py +0 -0
  75. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/trim.py +0 -0
  76. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/watermark.py +0 -0
  77. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/width.py +0 -0
  78. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/options/zoom.py +0 -0
  79. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/py.typed +0 -0
  80. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/signing.py +0 -0
  81. {imgproxykit-0.5.0 → imgproxykit-0.7.0}/imgproxykit/types.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.7.0
4
4
  Summary: A typed Python toolkit for building imgproxy URLs
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -23,15 +23,17 @@ Classifier: Typing :: Typed
23
23
  Provides-Extra: django
24
24
  Provides-Extra: drf
25
25
  Provides-Extra: fastapi
26
- Requires-Dist: django (>=5.2,<7) ; extra == "django"
27
- Requires-Dist: django (>=5.2,<7) ; extra == "drf"
26
+ Provides-Extra: litestar
27
+ Requires-Dist: django (>=6.1.3,<7) ; extra == "django"
28
+ Requires-Dist: django (>=6.1.3,<7) ; extra == "drf"
28
29
  Requires-Dist: djangorestframework (>=3.16,<4) ; extra == "drf"
29
- Requires-Dist: fastapi (>=0.135.2,<1) ; extra == "fastapi"
30
+ Requires-Dist: fastapi (>=0.165.0,<1) ; extra == "fastapi"
31
+ Requires-Dist: litestar (>=2.24,<3) ; extra == "litestar"
30
32
  Requires-Dist: typing-extensions (>=4.16,<5)
31
- Project-URL: Changelog, https://github.com/kondratevdev/imgproxykit/releases
33
+ Project-URL: Changelog, https://github.com/wemake-services/imgproxykit/releases
32
34
  Project-URL: Documentation, https://imgproxykit.readthedocs.io/en/latest/
33
- Project-URL: GitHub, https://github.com/kondratevdev/imgproxykit
34
- Project-URL: Issues, https://github.com/kondratevdev/imgproxykit/issues
35
+ Project-URL: GitHub, https://github.com/wemake-services/imgproxykit
36
+ Project-URL: Issues, https://github.com/wemake-services/imgproxykit/issues
35
37
  Description-Content-Type: text/markdown
36
38
 
37
39
  <h1 align="center">imgproxykit</h1>
@@ -42,14 +44,19 @@ Description-Content-Type: text/markdown
42
44
 
43
45
  <div align="center">
44
46
 
45
- [![Tests Result](https://img.shields.io/github/actions/workflow/status/kondratevdev/imgproxykit/test.yml?branch=master&label=tests&labelColor=black&color=blue)](https://github.com/kondratevdev/imgproxykit/actions/workflows/test.yml)
47
+ [![Tests Result](https://img.shields.io/github/actions/workflow/status/wemake-services/imgproxykit/test.yml?branch=master&label=tests&labelColor=black&color=blue)](https://github.com/wemake-services/imgproxykit/actions/workflows/test.yml)
46
48
  [![PyPI Version](https://img.shields.io/pypi/v/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
47
49
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/imgproxykit?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=BLUE&left_text=downloads)](https://pepy.tech/projects/imgproxykit)
48
50
  [![Supported Python Version](https://img.shields.io/pypi/pyversions/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
49
51
  [![License](https://img.shields.io/badge/license-MIT-blue.svg?labelColor=black)](LICENSE)
52
+ [![DeepWiki](https://img.shields.io/badge/deepwiki-ask-blue?labelColor=black)](https://deepwiki.com/wemake-services/imgproxykit)
50
53
 
51
54
  </div>
52
55
 
56
+ > Build [imgproxy](https://imgproxy.net/) URLs with typed Python options and
57
+ > reusable transformations. Define image settings once, compose them for
58
+ > different use cases, and generate named variants from a single source.
59
+
53
60
  ## Features
54
61
 
55
62
  - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
@@ -57,7 +64,7 @@ Description-Content-Type: text/markdown
57
64
  - [x] Immutable, reusable transforms combining typed options and scalar arguments
58
65
  - [x] Variants: generate multiple image URLs from a reusable set of transforms
59
66
  - [x] Support for named presets configured on your `imgproxy` server
60
- - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
67
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI`, `Litestar` integration
61
68
 
62
69
  ---------
63
70
 
@@ -72,16 +79,19 @@ pip install imgproxykit
72
79
 
73
80
  There are several included extras:
74
81
 
75
- - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
76
- with settings, shortcuts, and template tags
82
+ - `'imgproxykit[django]'` provides [Django](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
83
+ and [Django-Modern-REST](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/dmr.html)
84
+ integrations with shortcuts, template tags, and client configuration through Django settings
77
85
  - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
78
86
  with serializer fields for image URLs and named variants
79
87
  - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
80
- with client registration and dependency injection
88
+ with a dependency for injecting the client into route handlers
89
+ - `'imgproxykit[litestar]'` provides [Litestar integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/litestar.html)
90
+ with a plugin that injects the client into route handlers
81
91
 
82
92
  ## Examples
83
93
 
84
- ### Single URL
94
+ ### Generate a thumbnail URL
85
95
 
86
96
  Build a URL for a cropped `webp` thumbnail:
87
97
 
@@ -103,7 +113,7 @@ Build a URL for a cropped `webp` thumbnail:
103
113
 
104
114
  ```
105
115
 
106
- The generated URL has this structure, with the source URL encoded as URL-safe Base64:
116
+ The generated URL has this structure, with the source URL encoded as URL-safe `base64`:
107
117
 
108
118
  ```text
109
119
  https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
@@ -111,7 +121,7 @@ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<
111
121
 
112
122
  `thumbnail_url` points to a cropped `webp` thumbnail.
113
123
 
114
- ### Variants
124
+ ### Generate image variants
115
125
 
116
126
  Build variants by extending a shared transform with a width for each size:
117
127
 
@@ -131,12 +141,18 @@ Build variants by extending a shared transform with a width for each size:
131
141
  >>> source_url = 'https://originals.example.com/products/backpack.jpg'
132
142
  >>> # Build one URL per variant for the same source image.
133
143
  >>> product_urls = client.variants(source=source_url, variants=products)
134
- >>> small_url = product_urls['small'] # Access a URL by its variant name.
135
144
 
136
145
  ```
137
146
 
138
- `product_urls` contains a URL for each size, all using the shared quality
139
- and WebP format.
147
+ `product_urls` maps each variant name to its generated URL:
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
 
@@ -150,7 +166,7 @@ and WebP format.
150
166
 
151
167
  See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
152
168
  Bug reports and feature requests are welcome on the
153
- [issue tracker](https://github.com/kondratevdev/imgproxykit/issues).
169
+ [issue tracker](https://github.com/wemake-services/imgproxykit/issues).
154
170
 
155
171
  ## License
156
172
 
@@ -6,14 +6,19 @@
6
6
 
7
7
  <div align="center">
8
8
 
9
- [![Tests Result](https://img.shields.io/github/actions/workflow/status/kondratevdev/imgproxykit/test.yml?branch=master&label=tests&labelColor=black&color=blue)](https://github.com/kondratevdev/imgproxykit/actions/workflows/test.yml)
9
+ [![Tests Result](https://img.shields.io/github/actions/workflow/status/wemake-services/imgproxykit/test.yml?branch=master&label=tests&labelColor=black&color=blue)](https://github.com/wemake-services/imgproxykit/actions/workflows/test.yml)
10
10
  [![PyPI Version](https://img.shields.io/pypi/v/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
11
11
  [![PyPI Downloads](https://static.pepy.tech/personalized-badge/imgproxykit?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=BLUE&left_text=downloads)](https://pepy.tech/projects/imgproxykit)
12
12
  [![Supported Python Version](https://img.shields.io/pypi/pyversions/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
13
13
  [![License](https://img.shields.io/badge/license-MIT-blue.svg?labelColor=black)](LICENSE)
14
+ [![DeepWiki](https://img.shields.io/badge/deepwiki-ask-blue?labelColor=black)](https://deepwiki.com/wemake-services/imgproxykit)
14
15
 
15
16
  </div>
16
17
 
18
+ > Build [imgproxy](https://imgproxy.net/) URLs with typed Python options and
19
+ > reusable transformations. Define image settings once, compose them for
20
+ > different use cases, and generate named variants from a single source.
21
+
17
22
  ## Features
18
23
 
19
24
  - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
@@ -21,7 +26,7 @@
21
26
  - [x] Immutable, reusable transforms combining typed options and scalar arguments
22
27
  - [x] Variants: generate multiple image URLs from a reusable set of transforms
23
28
  - [x] Support for named presets configured on your `imgproxy` server
24
- - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
29
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI`, `Litestar` integration
25
30
 
26
31
  ---------
27
32
 
@@ -36,16 +41,19 @@ pip install imgproxykit
36
41
 
37
42
  There are several included extras:
38
43
 
39
- - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
40
- with settings, shortcuts, and template tags
44
+ - `'imgproxykit[django]'` provides [Django](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
45
+ and [Django-Modern-REST](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/dmr.html)
46
+ integrations with shortcuts, template tags, and client configuration through Django settings
41
47
  - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
42
48
  with serializer fields for image URLs and named variants
43
49
  - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
44
- with client registration and dependency injection
50
+ with a dependency for injecting the client into route handlers
51
+ - `'imgproxykit[litestar]'` provides [Litestar integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/litestar.html)
52
+ with a plugin that injects the client into route handlers
45
53
 
46
54
  ## Examples
47
55
 
48
- ### Single URL
56
+ ### Generate a thumbnail URL
49
57
 
50
58
  Build a URL for a cropped `webp` thumbnail:
51
59
 
@@ -67,7 +75,7 @@ Build a URL for a cropped `webp` thumbnail:
67
75
 
68
76
  ```
69
77
 
70
- The generated URL has this structure, with the source URL encoded as URL-safe Base64:
78
+ The generated URL has this structure, with the source URL encoded as URL-safe `base64`:
71
79
 
72
80
  ```text
73
81
  https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
@@ -75,7 +83,7 @@ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<
75
83
 
76
84
  `thumbnail_url` points to a cropped `webp` thumbnail.
77
85
 
78
- ### Variants
86
+ ### Generate image variants
79
87
 
80
88
  Build variants by extending a shared transform with a width for each size:
81
89
 
@@ -95,12 +103,18 @@ Build variants by extending a shared transform with a width for each size:
95
103
  >>> source_url = 'https://originals.example.com/products/backpack.jpg'
96
104
  >>> # Build one URL per variant for the same source image.
97
105
  >>> product_urls = client.variants(source=source_url, variants=products)
98
- >>> small_url = product_urls['small'] # Access a URL by its variant name.
99
106
 
100
107
  ```
101
108
 
102
- `product_urls` contains a URL for each size, all using the shared quality
103
- and WebP format.
109
+ `product_urls` maps each variant name to its generated URL:
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
 
@@ -114,7 +128,7 @@ and WebP format.
114
128
 
115
129
  See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
116
130
  Bug reports and feature requests are welcome on the
117
- [issue tracker](https://github.com/kondratevdev/imgproxykit/issues).
131
+ [issue tracker](https://github.com/wemake-services/imgproxykit/issues).
118
132
 
119
133
  ## License
120
134
 
@@ -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
  """
@@ -34,11 +31,8 @@ class Client:
34
31
  '_url_signer',
35
32
  )
36
33
 
37
- #: Component that resolves processing parameters and builds unsigned paths.
38
34
  path_serializer_cls: ClassVar[type[PathSerializer]] = PathSerializer
39
- #: Component that signs paths or returns the unsigned URL marker.
40
35
  url_signer_cls: ClassVar[type[UrlSigner]] = UrlSigner
41
- #: Component that validates dataclass variant declarations.
42
36
  variants_resolver_cls: ClassVar[type[DataclassVariantsResolver]] = (
43
37
  DataclassVariantsResolver
44
38
  )
@@ -55,6 +49,7 @@ class Client:
55
49
  unsigned_marker: str = 'unsafe',
56
50
  argument_separator: str = ':',
57
51
  use_short_options: bool = False,
52
+ only_presets: bool = False,
58
53
  ) -> None: ...
59
54
 
60
55
  @overload
@@ -69,6 +64,7 @@ class Client:
69
64
  signature_size: int = 32,
70
65
  argument_separator: str = ':',
71
66
  use_short_options: bool = False,
67
+ only_presets: bool = False,
72
68
  ) -> None: ...
73
69
 
74
70
  def __init__( # noqa: WPS211
@@ -83,6 +79,7 @@ class Client:
83
79
  unsigned_marker: str = 'unsafe',
84
80
  argument_separator: str = ':',
85
81
  use_short_options: bool = False,
82
+ only_presets: bool = False,
86
83
  ) -> None:
87
84
  """
88
85
  Configure the imgproxy address and create the client components.
@@ -120,6 +117,12 @@ class Client:
120
117
  <https://docs.imgproxy.net/usage/processing#source-url>`__.
121
118
  use_short_options: Use short processing option aliases when
122
119
  available, falling back to full names. Defaults to ``False``.
120
+ only_presets: Match ``IMGPROXY_ONLY_PRESETS`` on the server.
121
+ Require nonempty Preset options, optionally combined with Format
122
+ options. The last format becomes a source suffix. Other
123
+ processing options are rejected. Defaults to ``False``.
124
+ See `IMGPROXY_ONLY_PRESETS
125
+ <https://docs.imgproxy.net/usage/presets#only-presets>`__.
123
126
 
124
127
  Raises:
125
128
  ValueError: With the default signer, if only one signing
@@ -147,6 +150,7 @@ class Client:
147
150
  argument_separator=argument_separator,
148
151
  use_short_options=use_short_options,
149
152
  source_encoding=source_encoding,
153
+ only_presets=only_presets,
150
154
  )
151
155
  self._url_signer = self.url_signer_cls(
152
156
  key=key,
@@ -182,8 +186,7 @@ class Client:
182
186
 
183
187
  Returns:
184
188
  The complete imgproxy URL, signed when credentials were supplied
185
- or containing the unsigned marker otherwise. No network request
186
- is made.
189
+ or containing the unsigned marker otherwise.
187
190
  """
188
191
  path = self._path_serializer(source, transform=transform)
189
192
  signature = self._url_signer(path)
@@ -210,7 +213,7 @@ class Client:
210
213
  source: str,
211
214
  *,
212
215
  variants: Mapping[Key, Transform] | type['DataclassInstance'],
213
- ) -> _VariantsResult[Key]:
216
+ ) -> VariantsResult[Key]:
214
217
  """
215
218
  Build named URLs for one source using complete transformations.
216
219
 
@@ -227,7 +230,6 @@ class Client:
227
230
  An empty mapping produces an empty dictionary.
228
231
  A dataclass class produces a new instance of that exact class,
229
232
  with a generated URL in every field.
230
- No network request is made.
231
233
  """
232
234
  transforms = (
233
235
  variants
@@ -238,4 +240,4 @@ class Client:
238
240
  name: self.url(source, transform=transform) # ty: ignore[invalid-argument-type]
239
241
  for name, transform in transforms.items()
240
242
  }
241
- return urls if isinstance(variants, Mapping) else variants(**urls) # ty: ignore[invalid-return-type, invalid-argument-type]
243
+ return urls if isinstance(variants, Mapping) else variants(**urls) # ty: ignore[invalid-explicit-return, invalid-argument-type]
@@ -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,7 +9,9 @@ from typing_extensions import TypedDict
9
9
  from imgproxykit.transform import Transform
10
10
  from imgproxykit.types import SourceEncoding
11
11
 
12
- #: Django setting containing the imgproxy client configuration.
12
+ if TYPE_CHECKING:
13
+ from _typeshed import DataclassInstance
14
+
13
15
  IMGPROXYKIT_SETTINGS: Final = 'IMGPROXYKIT'
14
16
 
15
17
 
@@ -25,6 +27,7 @@ class ClientSettings(enum.StrEnum):
25
27
  unsigned_marker = 'unsigned_marker'
26
28
  argument_separator = 'argument_separator'
27
29
  use_short_options = 'use_short_options'
30
+ only_presets = 'only_presets'
28
31
  source_encoding = 'source_encoding'
29
32
 
30
33
 
@@ -42,35 +45,37 @@ class Settings(enum.StrEnum):
42
45
  class ClientSettingsDict(TypedDict, total=False, closed=True):
43
46
  """Describe client constructor options for static type checking."""
44
47
 
45
- #: Public imgproxy address, including any deployment path prefix.
46
48
  base_url: Required[str]
47
- #: Hex-encoded signing key matching the imgproxy server.
49
+ """Public imgproxy address, including any deployment path prefix."""
48
50
  key: str | None
49
- #: Hex-encoded signing salt matching the imgproxy server.
51
+ """Hex-encoded signing key matching the imgproxy server."""
50
52
  salt: str | None
51
- #: Positive signature digest byte count; must match the server.
53
+ """Hex-encoded signing salt matching the imgproxy server."""
52
54
  signature_size: int
53
- #: Signature marker used when signing credentials are omitted.
55
+ """Positive signature digest byte count; must match the server."""
54
56
  unsigned_marker: str
55
- #: Processing argument separator; must match the server.
57
+ """Signature marker used when signing credentials are omitted."""
56
58
  argument_separator: str
57
- #: Use short processing option aliases when available.
59
+ """Processing argument separator; must match the server."""
58
60
  use_short_options: bool
59
- #: Source URL representation using Base64 or percent-encoded plain mode.
61
+ """Use short processing option aliases when available."""
62
+ only_presets: bool
63
+ """Serialize only preset options, ignoring other processing options."""
60
64
  source_encoding: SourceEncoding
65
+ """Source URL representation using Base64 or percent-encoded plain mode."""
61
66
 
62
67
 
63
68
  class SettingsDict(TypedDict, total=False, closed=True):
64
69
  """Describe the IMGPROXYKIT dictionary for static type checking."""
65
70
 
66
- #: Client constructor options; defaults remain in the core Client.
67
71
  client: Required[ClientSettingsDict]
68
- #: Named Python transformations, distinct from imgproxy server presets.
72
+ """Client constructor options; defaults remain in the core Client."""
69
73
  transforms: Mapping[str, Transform]
70
- #: Named sets of transformations; objects can be shared with transforms.
71
- variants: Mapping[str, Mapping[str, Transform]]
72
- #: Convert the original source to a URI, including empty file fields.
74
+ """Named Python transformations, distinct from imgproxy server presets."""
75
+ variants: Mapping[str, Mapping[str, Transform] | type['DataclassInstance']]
76
+ """Named sets of transformations; objects can be shared with transforms."""
73
77
  source_resolver: Callable[[str | FieldFile], str] | str
78
+ """Convert the original source to a URI, including empty file fields."""
74
79
 
75
80
 
76
81
  assert set(SettingsDict.__annotations__) == set(Settings), ( # noqa: S101
@@ -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
  """
@@ -47,7 +51,7 @@ class ImgproxyURLField(serializers.URLField):
47
51
 
48
52
  # Empty sources produce None, which URLField's return type excludes.
49
53
  @override
50
- def to_representation( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
54
+ def to_representation( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[incompatible-method-override]
51
55
  self,
52
56
  value: str | FieldFile | None,
53
57
  ) -> str | None:
@@ -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."""
@@ -106,7 +111,7 @@ class ImgproxyVariantsField(serializers.DictField):
106
111
 
107
112
  # DictField's types exclude source strings, model files, and None output.
108
113
  @override
109
- def to_representation( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
114
+ def to_representation( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[incompatible-method-override]
110
115
  self,
111
116
  value: str | FieldFile | None, # type: ignore[override]
112
117
  ) -> dict[str, str] | None:
@@ -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
+ )