imgproxykit 0.3.0__tar.gz → 0.5.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 (83) hide show
  1. imgproxykit-0.5.0/PKG-INFO +164 -0
  2. imgproxykit-0.5.0/README.md +127 -0
  3. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/client.py +100 -25
  4. imgproxykit-0.5.0/imgproxykit/integrations/django/__init__.py +29 -0
  5. imgproxykit-0.5.0/imgproxykit/integrations/django/apps.py +8 -0
  6. imgproxykit-0.5.0/imgproxykit/integrations/django/client.py +39 -0
  7. imgproxykit-0.5.0/imgproxykit/integrations/django/settings.py +121 -0
  8. imgproxykit-0.5.0/imgproxykit/integrations/django/shortcuts.py +77 -0
  9. imgproxykit-0.5.0/imgproxykit/integrations/django/sources.py +42 -0
  10. imgproxykit-0.5.0/imgproxykit/integrations/django/templatetags/imgproxykit.py +12 -0
  11. imgproxykit-0.5.0/imgproxykit/integrations/drf/__init__.py +16 -0
  12. imgproxykit-0.5.0/imgproxykit/integrations/drf/serializers.py +117 -0
  13. imgproxykit-0.5.0/imgproxykit/integrations/fastapi/__init__.py +13 -0
  14. imgproxykit-0.5.0/imgproxykit/integrations/fastapi/dependencies.py +53 -0
  15. imgproxykit-0.5.0/imgproxykit/internal/__init__.py +0 -0
  16. imgproxykit-0.5.0/imgproxykit/internal/encoding.py +31 -0
  17. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/auto_rotate.py +2 -3
  18. imgproxykit-0.5.0/imgproxykit/options/background.py +67 -0
  19. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/base.py +12 -7
  20. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/blur.py +2 -3
  21. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/cache_buster.py +3 -3
  22. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/crop.py +18 -15
  23. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/dpr.py +1 -3
  24. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/enforce_thumbnail.py +2 -3
  25. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/enlarge.py +2 -3
  26. imgproxykit-0.5.0/imgproxykit/options/expires.py +57 -0
  27. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/extend.py +18 -14
  28. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/extend_aspect_ratio.py +18 -14
  29. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/filename.py +3 -3
  30. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/flip.py +3 -3
  31. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/format.py +3 -6
  32. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/format_quality.py +3 -3
  33. imgproxykit-0.5.0/imgproxykit/options/gravity.py +152 -0
  34. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/height.py +2 -3
  35. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/keep_copyright.py +2 -3
  36. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_animation_frame_resolution.py +2 -3
  37. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_animation_frames.py +2 -3
  38. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_bytes.py +2 -3
  39. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_result_dimension.py +2 -3
  40. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_src_file_size.py +2 -3
  41. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/max_src_resolution.py +2 -3
  42. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/min_height.py +2 -3
  43. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/min_width.py +2 -3
  44. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/padding.py +21 -5
  45. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/pixelate.py +2 -3
  46. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/preserve_hdr.py +2 -3
  47. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/preset.py +5 -5
  48. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/quality.py +2 -6
  49. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/raw.py +1 -3
  50. imgproxykit-0.5.0/imgproxykit/options/resize.py +149 -0
  51. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/resizing_type.py +3 -3
  52. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/return_attachment.py +2 -3
  53. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/rotate.py +2 -3
  54. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/sharpen.py +2 -3
  55. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/size.py +3 -3
  56. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/skip_processing.py +3 -3
  57. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/strip_color_profile.py +2 -3
  58. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/strip_metadata.py +2 -3
  59. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/trim.py +32 -6
  60. imgproxykit-0.5.0/imgproxykit/options/watermark.py +236 -0
  61. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/width.py +2 -3
  62. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/zoom.py +3 -3
  63. imgproxykit-0.5.0/imgproxykit/py.typed +0 -0
  64. imgproxykit-0.5.0/imgproxykit/serialization.py +149 -0
  65. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/signing.py +5 -7
  66. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/transform.py +28 -23
  67. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/types.py +24 -69
  68. imgproxykit-0.5.0/imgproxykit/variants.py +91 -0
  69. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/pyproject.toml +50 -17
  70. imgproxykit-0.3.0/PKG-INFO +0 -135
  71. imgproxykit-0.3.0/README.md +0 -106
  72. imgproxykit-0.3.0/imgproxykit/internal/encoding.py +0 -12
  73. imgproxykit-0.3.0/imgproxykit/options/background.py +0 -45
  74. imgproxykit-0.3.0/imgproxykit/options/expires.py +0 -27
  75. imgproxykit-0.3.0/imgproxykit/options/gravity.py +0 -52
  76. imgproxykit-0.3.0/imgproxykit/options/resize.py +0 -54
  77. imgproxykit-0.3.0/imgproxykit/options/watermark.py +0 -59
  78. imgproxykit-0.3.0/imgproxykit/serialization.py +0 -118
  79. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/LICENSE +0 -0
  80. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/__init__.py +0 -0
  81. {imgproxykit-0.3.0/imgproxykit/internal → imgproxykit-0.5.0/imgproxykit/integrations}/__init__.py +0 -0
  82. /imgproxykit-0.3.0/imgproxykit/py.typed → /imgproxykit-0.5.0/imgproxykit/integrations/django/templatetags/__init__.py +0 -0
  83. {imgproxykit-0.3.0 → imgproxykit-0.5.0}/imgproxykit/options/__init__.py +0 -0
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: imgproxykit
3
+ Version: 0.5.0
4
+ Summary: A typed Python toolkit for building imgproxy URLs
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Keywords: image-processing,image-transformation,images,imgproxy,url-builder
8
+ Author: Alexander Kondratev
9
+ Author-email: mail@kondratev.dev
10
+ Requires-Python: >=3.12,<4
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Provides-Extra: django
24
+ Provides-Extra: drf
25
+ Provides-Extra: fastapi
26
+ Requires-Dist: django (>=5.2,<7) ; extra == "django"
27
+ Requires-Dist: django (>=5.2,<7) ; extra == "drf"
28
+ Requires-Dist: djangorestframework (>=3.16,<4) ; extra == "drf"
29
+ Requires-Dist: fastapi (>=0.135.2,<1) ; extra == "fastapi"
30
+ Requires-Dist: typing-extensions (>=4.16,<5)
31
+ Project-URL: Changelog, https://github.com/kondratevdev/imgproxykit/releases
32
+ 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
+ Description-Content-Type: text/markdown
36
+
37
+ <h1 align="center">imgproxykit</h1>
38
+
39
+ <p align="center">
40
+ <em>A typed Python toolkit for building imgproxy URLs.</em>
41
+ </p>
42
+
43
+ <div align="center">
44
+
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)
46
+ [![PyPI Version](https://img.shields.io/pypi/v/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
47
+ [![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
+ [![Supported Python Version](https://img.shields.io/pypi/pyversions/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
49
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg?labelColor=black)](LICENSE)
50
+
51
+ </div>
52
+
53
+ ## Features
54
+
55
+ - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
56
+ - [x] Signed URLs using your `imgproxy` server's `key` and `salt`
57
+ - [x] Immutable, reusable transforms combining typed options and scalar arguments
58
+ - [x] Variants: generate multiple image URLs from a reusable set of transforms
59
+ - [x] Support for named presets configured on your `imgproxy` server
60
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
61
+
62
+ ---------
63
+
64
+ ## Installation
65
+
66
+ Requires **Python 3.12+**. A running [imgproxy](https://github.com/imgproxy/imgproxy)
67
+ server is needed to serve images from the generated URLs.
68
+
69
+ ```bash
70
+ pip install imgproxykit
71
+ ```
72
+
73
+ There are several included extras:
74
+
75
+ - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
76
+ with settings, shortcuts, and template tags
77
+ - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
78
+ with serializer fields for image URLs and named variants
79
+ - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
80
+ with client registration and dependency injection
81
+
82
+ ## Examples
83
+
84
+ ### Single URL
85
+
86
+ Build a URL for a cropped `webp` thumbnail:
87
+
88
+ ```python
89
+ >>> from imgproxykit import Client, Transform
90
+ >>> from imgproxykit.options import Resize
91
+
92
+ >>> # Public URL of your imgproxy server.
93
+ >>> client = Client('https://imgproxy.example.com')
94
+
95
+ >>> thumbnail = Transform(
96
+ ... Resize.fill(width=300, height=300), # Pass typed option objects.
97
+ ... quality=80, # Or scalar keywords, equivalent to Quality(80).
98
+ ... format='webp',
99
+ ... )
100
+
101
+ >>> source_url = 'https://originals.example.com/products/backpack.jpg'
102
+ >>> thumbnail_url = client.url(source=source_url, transform=thumbnail)
103
+
104
+ ```
105
+
106
+ The generated URL has this structure, with the source URL encoded as URL-safe Base64:
107
+
108
+ ```text
109
+ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
110
+ ```
111
+
112
+ `thumbnail_url` points to a cropped `webp` thumbnail.
113
+
114
+ ### Variants
115
+
116
+ Build variants by extending a shared transform with a width for each size:
117
+
118
+ ```python
119
+ >>> from imgproxykit import Client, Transform
120
+
121
+ >>> client = Client('https://imgproxy.example.com')
122
+
123
+ >>> # Share quality and output format across all variants.
124
+ >>> base = Transform(quality=85, format='webp')
125
+ >>> products = {
126
+ ... 'small': base.extend(width=320),
127
+ ... 'medium': base.extend(width=640),
128
+ ... 'large': base.extend(width=1280),
129
+ ... }
130
+
131
+ >>> source_url = 'https://originals.example.com/products/backpack.jpg'
132
+ >>> # Build one URL per variant for the same source image.
133
+ >>> product_urls = client.variants(source=source_url, variants=products)
134
+ >>> small_url = product_urls['small'] # Access a URL by its variant name.
135
+
136
+ ```
137
+
138
+ `product_urls` contains a URL for each size, all using the shared quality
139
+ and WebP format.
140
+
141
+ ## Next steps
142
+
143
+ - Read the [documentation](https://imgproxykit.readthedocs.io/en/latest/)
144
+ for client configuration, transformations, variants, and processing options.
145
+ - Check the [changelog](https://imgproxykit.readthedocs.io/en/latest/pages/changelog.html)
146
+ for new features, fixes, and breaking changes.
147
+ - Find published releases on [PyPI](https://pypi.org/project/imgproxykit/).
148
+
149
+ ## Contributing
150
+
151
+ See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
152
+ Bug reports and feature requests are welcome on the
153
+ [issue tracker](https://github.com/kondratevdev/imgproxykit/issues).
154
+
155
+ ## License
156
+
157
+ [MIT](LICENSE)
158
+
159
+ ## Credits
160
+
161
+ Generated with
162
+ [`wemake-python-package`](https://github.com/wemake-services/wemake-python-package)
163
+ ([template version](https://github.com/wemake-services/wemake-python-package/tree/47d9dddd29da8d6d3d1a403f8a143b323a812083)).
164
+
@@ -0,0 +1,127 @@
1
+ <h1 align="center">imgproxykit</h1>
2
+
3
+ <p align="center">
4
+ <em>A typed Python toolkit for building imgproxy URLs.</em>
5
+ </p>
6
+
7
+ <div align="center">
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)
10
+ [![PyPI Version](https://img.shields.io/pypi/v/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
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
+ [![Supported Python Version](https://img.shields.io/pypi/pyversions/imgproxykit.svg?labelColor=black&color=blue)](https://pypi.org/project/imgproxykit/)
13
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg?labelColor=black)](LICENSE)
14
+
15
+ </div>
16
+
17
+ ## Features
18
+
19
+ - [x] Fully typed and checked with `mypy`, `pyright`, `ty` and `pyrefly` in strict modes
20
+ - [x] Signed URLs using your `imgproxy` server's `key` and `salt`
21
+ - [x] Immutable, reusable transforms combining typed options and scalar arguments
22
+ - [x] Variants: generate multiple image URLs from a reusable set of transforms
23
+ - [x] Support for named presets configured on your `imgproxy` server
24
+ - [x] `Django`, `Django Modern REST`, `Django REST Framework`, `FastAPI` integration
25
+
26
+ ---------
27
+
28
+ ## Installation
29
+
30
+ Requires **Python 3.12+**. A running [imgproxy](https://github.com/imgproxy/imgproxy)
31
+ server is needed to serve images from the generated URLs.
32
+
33
+ ```bash
34
+ pip install imgproxykit
35
+ ```
36
+
37
+ There are several included extras:
38
+
39
+ - `'imgproxykit[django]'` provides [Django integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/django.html)
40
+ with settings, shortcuts, and template tags
41
+ - `'imgproxykit[drf]'` provides [Django REST Framework integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/drf.html)
42
+ with serializer fields for image URLs and named variants
43
+ - `'imgproxykit[fastapi]'` provides [FastAPI integration](https://imgproxykit.readthedocs.io/en/latest/pages/integrations/fastapi.html)
44
+ with client registration and dependency injection
45
+
46
+ ## Examples
47
+
48
+ ### Single URL
49
+
50
+ Build a URL for a cropped `webp` thumbnail:
51
+
52
+ ```python
53
+ >>> from imgproxykit import Client, Transform
54
+ >>> from imgproxykit.options import Resize
55
+
56
+ >>> # Public URL of your imgproxy server.
57
+ >>> client = Client('https://imgproxy.example.com')
58
+
59
+ >>> thumbnail = Transform(
60
+ ... Resize.fill(width=300, height=300), # Pass typed option objects.
61
+ ... quality=80, # Or scalar keywords, equivalent to Quality(80).
62
+ ... format='webp',
63
+ ... )
64
+
65
+ >>> source_url = 'https://originals.example.com/products/backpack.jpg'
66
+ >>> thumbnail_url = client.url(source=source_url, transform=thumbnail)
67
+
68
+ ```
69
+
70
+ The generated URL has this structure, with the source URL encoded as URL-safe Base64:
71
+
72
+ ```text
73
+ https://imgproxy.example.com/unsafe/resize:fill:300:300/quality:80/format:webp/<encoded-source>
74
+ ```
75
+
76
+ `thumbnail_url` points to a cropped `webp` thumbnail.
77
+
78
+ ### Variants
79
+
80
+ Build variants by extending a shared transform with a width for each size:
81
+
82
+ ```python
83
+ >>> from imgproxykit import Client, Transform
84
+
85
+ >>> client = Client('https://imgproxy.example.com')
86
+
87
+ >>> # Share quality and output format across all variants.
88
+ >>> base = Transform(quality=85, format='webp')
89
+ >>> products = {
90
+ ... 'small': base.extend(width=320),
91
+ ... 'medium': base.extend(width=640),
92
+ ... 'large': base.extend(width=1280),
93
+ ... }
94
+
95
+ >>> source_url = 'https://originals.example.com/products/backpack.jpg'
96
+ >>> # Build one URL per variant for the same source image.
97
+ >>> product_urls = client.variants(source=source_url, variants=products)
98
+ >>> small_url = product_urls['small'] # Access a URL by its variant name.
99
+
100
+ ```
101
+
102
+ `product_urls` contains a URL for each size, all using the shared quality
103
+ and WebP format.
104
+
105
+ ## Next steps
106
+
107
+ - Read the [documentation](https://imgproxykit.readthedocs.io/en/latest/)
108
+ for client configuration, transformations, variants, and processing options.
109
+ - Check the [changelog](https://imgproxykit.readthedocs.io/en/latest/pages/changelog.html)
110
+ for new features, fixes, and breaking changes.
111
+ - Find published releases on [PyPI](https://pypi.org/project/imgproxykit/).
112
+
113
+ ## Contributing
114
+
115
+ See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
116
+ Bug reports and feature requests are welcome on the
117
+ [issue tracker](https://github.com/kondratevdev/imgproxykit/issues).
118
+
119
+ ## License
120
+
121
+ [MIT](LICENSE)
122
+
123
+ ## Credits
124
+
125
+ Generated with
126
+ [`wemake-python-package`](https://github.com/wemake-services/wemake-python-package)
127
+ ([template version](https://github.com/wemake-services/wemake-python-package/tree/47d9dddd29da8d6d3d1a403f8a143b323a812083)).
@@ -1,8 +1,18 @@
1
- from typing import ClassVar, overload
1
+ from collections.abc import Mapping
2
+ from typing import TYPE_CHECKING, ClassVar, overload
2
3
 
3
4
  from imgproxykit.serialization import PathSerializer
4
5
  from imgproxykit.signing import UrlSigner
5
6
  from imgproxykit.transform import Transform
7
+ from imgproxykit.types import SourceEncoding
8
+ from imgproxykit.variants import DataclassVariantsResolver
9
+
10
+ if TYPE_CHECKING:
11
+ from _typeshed import DataclassInstance
12
+
13
+ type _VariantsResult[Key: str] = (
14
+ dict[Key, str] | dict[str, str] | DataclassInstance
15
+ )
6
16
 
7
17
 
8
18
  class Client:
@@ -10,17 +20,12 @@ class Client:
10
20
  Build imgproxy URLs from Python transforms or server presets.
11
21
 
12
22
  Stores the imgproxy address and signing configuration for reuse across
13
- images. Each call to :meth:`url` returns a URL string; imgproxy loads
14
- the source and processes the image when that URL is requested.
23
+ images. Imgproxy loads the source and processes the image when
24
+ that URL is requested.
15
25
 
16
26
  Pass processing options through :class:`~imgproxykit.Transform` as
17
27
  option instances or scalar keyword arguments. Preset options reference
18
28
  names configured on the imgproxy server.
19
-
20
- Subclass this client and override :attr:`path_serializer_cls` or
21
- :attr:`url_signer_cls` to customize path construction or signing.
22
- Each client creates its own instances of these components.
23
-
24
29
  """
25
30
 
26
31
  __slots__ = (
@@ -33,6 +38,10 @@ class Client:
33
38
  path_serializer_cls: ClassVar[type[PathSerializer]] = PathSerializer
34
39
  #: Component that signs paths or returns the unsigned URL marker.
35
40
  url_signer_cls: ClassVar[type[UrlSigner]] = UrlSigner
41
+ #: Component that validates dataclass variant declarations.
42
+ variants_resolver_cls: ClassVar[type[DataclassVariantsResolver]] = (
43
+ DataclassVariantsResolver
44
+ )
36
45
 
37
46
  @overload
38
47
  def __init__(
@@ -42,8 +51,10 @@ class Client:
42
51
  *,
43
52
  key: None = None,
44
53
  salt: None = None,
45
- unsigned_signature: str = 'unsafe',
46
- arguments_separator: str = ':',
54
+ source_encoding: SourceEncoding = 'base64',
55
+ unsigned_marker: str = 'unsafe',
56
+ argument_separator: str = ':',
57
+ use_short_options: bool = False,
47
58
  ) -> None: ...
48
59
 
49
60
  @overload
@@ -54,8 +65,10 @@ class Client:
54
65
  *,
55
66
  key: str,
56
67
  salt: str,
68
+ source_encoding: SourceEncoding = 'base64',
57
69
  signature_size: int = 32,
58
- arguments_separator: str = ':',
70
+ argument_separator: str = ':',
71
+ use_short_options: bool = False,
59
72
  ) -> None: ...
60
73
 
61
74
  def __init__( # noqa: WPS211
@@ -65,9 +78,11 @@ class Client:
65
78
  *,
66
79
  key: str | None = None,
67
80
  salt: str | None = None,
81
+ source_encoding: SourceEncoding = 'base64',
68
82
  signature_size: int = 32,
69
- unsigned_signature: str = 'unsafe',
70
- arguments_separator: str = ':',
83
+ unsigned_marker: str = 'unsafe',
84
+ argument_separator: str = ':',
85
+ use_short_options: bool = False,
71
86
  ) -> None:
72
87
  """
73
88
  Configure the imgproxy address and create the client components.
@@ -82,29 +97,37 @@ class Client:
82
97
  stored as supplied, without validation.
83
98
  key: Nonempty hex-encoded signing key matching the server.
84
99
  Supply together with ``salt``; ``None`` selects unsigned mode.
100
+ See `IMGPROXY_KEY
101
+ <https://docs.imgproxy.net/configuration/options#url-signature>`__.
85
102
  salt: Nonempty hex-encoded signing salt matching the server.
86
103
  Supply together with ``key``; ``None`` selects unsigned mode.
104
+ See `IMGPROXY_SALT
105
+ <https://docs.imgproxy.net/configuration/options#url-signature>`__.
87
106
  signature_size: Positive digest byte count to encode. Must match
88
107
  the server's `IMGPROXY_SIGNATURE_SIZE
89
108
  <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
90
- Defaults to ``32``.
91
- Values of 32 or more use the full digest.
92
- unsigned_signature: URL marker used when key and salt are omitted.
109
+ unsigned_marker: URL marker used when key and salt are omitted.
93
110
  Defaults to ``'unsafe'``. With server signing enabled,
94
111
  configure this marker in `IMGPROXY_TRUSTED_SIGNATURES
95
112
  <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
96
- arguments_separator: Separator between processing option names
113
+ argument_separator: Separator between processing option names
97
114
  and their arguments. Must match the server's
98
115
  `IMGPROXY_ARGUMENTS_SEPARATOR
99
116
  <https://docs.imgproxy.net/latest/configuration/options#miscellaneous>`__.
100
- Defaults to ``':'``.
117
+ source_encoding: Source URL representation: ``'base64'`` or
118
+ ``'plain'`` with full percent-encoding. See
119
+ `imgproxy source URLs
120
+ <https://docs.imgproxy.net/usage/processing#source-url>`__.
121
+ use_short_options: Use short processing option aliases when
122
+ available, falling back to full names. Defaults to ``False``.
101
123
 
102
124
  Raises:
103
125
  ValueError: With the default signer, if only one signing
104
126
  credential is supplied, either is empty or invalid hex,
105
127
  or ``signature_size`` is not positive, even in unsigned mode.
106
128
 
107
- Examples:
129
+ Usage:
130
+
108
131
  Create an unsigned client:
109
132
 
110
133
  >>> from imgproxykit import Client
@@ -117,18 +140,19 @@ class Client:
117
140
  ... key='736563726574',
118
141
  ... salt='73616c74',
119
142
  ... )
120
-
121
143
  """
122
144
  # Prepare `base_url` only once pre instance
123
145
  self._base_url = base_url.rstrip('/')
124
146
  self._path_serializer = self.path_serializer_cls(
125
- arguments_separator=arguments_separator,
147
+ argument_separator=argument_separator,
148
+ use_short_options=use_short_options,
149
+ source_encoding=source_encoding,
126
150
  )
127
151
  self._url_signer = self.url_signer_cls(
128
152
  key=key,
129
153
  salt=salt,
130
154
  signature_size=signature_size,
131
- unsigned_signature=unsigned_signature,
155
+ unsigned_marker=unsigned_marker,
132
156
  )
133
157
 
134
158
  def url(
@@ -150,9 +174,9 @@ class Client:
150
174
 
151
175
  Args:
152
176
  source: Complete source URI understood by the imgproxy server.
153
- The default serializer encodes its UTF-8 representation as
154
- URL-safe Base64 without padding. The URI is neither validated
155
- nor resolved against ``base_url``.
177
+ The default serializer uses URL-safe Base64 without padding
178
+ or percent-encoding according to ``source_encoding``. The URI
179
+ is neither validated nor resolved against ``base_url``.
156
180
  transform: Reusable processing options and optional output format.
157
181
  Omit or pass ``None`` to add no processing options.
158
182
 
@@ -164,3 +188,54 @@ class Client:
164
188
  path = self._path_serializer(source, transform=transform)
165
189
  signature = self._url_signer(path)
166
190
  return f'{self._base_url}/{signature}{path}'
191
+
192
+ @overload
193
+ def variants[Key: str](
194
+ self,
195
+ source: str,
196
+ *,
197
+ variants: Mapping[Key, Transform],
198
+ ) -> dict[Key, str]: ...
199
+
200
+ @overload
201
+ def variants[VariantSet: DataclassInstance](
202
+ self,
203
+ source: str,
204
+ *,
205
+ variants: type[VariantSet],
206
+ ) -> VariantSet: ...
207
+
208
+ def variants[Key: str](
209
+ self,
210
+ source: str,
211
+ *,
212
+ variants: Mapping[Key, Transform] | type['DataclassInstance'],
213
+ ) -> _VariantsResult[Key]:
214
+ """
215
+ Build named URLs for one source using complete transformations.
216
+
217
+ Args:
218
+ source: Complete source URI understood by the imgproxy server.
219
+ variants: Names mapped to the transformation for each variant.
220
+ Alternatively, a dataclass class with fields declared as
221
+ ``Annotated[str, Transform(...)]``. Each transformation is
222
+ passed unchanged to :meth:`url`.
223
+
224
+ Returns:
225
+ A new dictionary preserving the input keys and iteration order.
226
+ The key type is preserved, including literal string unions.
227
+ An empty mapping produces an empty dictionary.
228
+ A dataclass class produces a new instance of that exact class,
229
+ with a generated URL in every field.
230
+ No network request is made.
231
+ """
232
+ transforms = (
233
+ variants
234
+ if isinstance(variants, Mapping)
235
+ else self.variants_resolver_cls(model=variants)()
236
+ )
237
+ urls = {
238
+ name: self.url(source, transform=transform) # ty: ignore[invalid-argument-type]
239
+ for name, transform in transforms.items()
240
+ }
241
+ return urls if isinstance(variants, Mapping) else variants(**urls) # ty: ignore[invalid-return-type, invalid-argument-type]
@@ -0,0 +1,29 @@
1
+ # Optional integrations check their dependencies before importing adapters.
2
+ # flake8: noqa: WPS412
3
+ try: # noqa: RUF067
4
+ import django # noqa: F401 # pyright: ignore[reportUnusedImport]
5
+ except ImportError as exc: # pragma: no cover
6
+ raise ImportError(
7
+ 'The Django integration requires Django. '
8
+ "Install it with `pip install 'imgproxykit[django]'`.",
9
+ ) from exc
10
+
11
+ from imgproxykit.integrations.django.client import get_client as get_client
12
+ from imgproxykit.integrations.django.settings import (
13
+ ClientSettings as ClientSettings,
14
+ )
15
+ from imgproxykit.integrations.django.settings import (
16
+ ClientSettingsDict as ClientSettingsDict,
17
+ )
18
+ from imgproxykit.integrations.django.settings import (
19
+ Settings as Settings,
20
+ )
21
+ from imgproxykit.integrations.django.settings import (
22
+ SettingsDict as SettingsDict,
23
+ )
24
+ from imgproxykit.integrations.django.shortcuts import (
25
+ imgproxy_url as imgproxy_url,
26
+ )
27
+ from imgproxykit.integrations.django.shortcuts import (
28
+ imgproxy_variants as imgproxy_variants,
29
+ )
@@ -0,0 +1,8 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class ImgproxyKitConfig(AppConfig):
5
+ """Django application configuration for imgproxykit."""
6
+
7
+ name = 'imgproxykit.integrations.django'
8
+ label = 'imgproxykit'
@@ -0,0 +1,39 @@
1
+ from functools import lru_cache
2
+ from typing import Any
3
+
4
+ from django.core.signals import setting_changed
5
+ from django.dispatch import receiver
6
+
7
+ from imgproxykit.client import Client
8
+ from imgproxykit.integrations.django.settings import (
9
+ IMGPROXYKIT_SETTINGS,
10
+ ClientSettings,
11
+ Settings,
12
+ get_config,
13
+ )
14
+
15
+
16
+ @lru_cache(maxsize=1)
17
+ def get_client() -> Client:
18
+ """
19
+ Return the cached client configured by IMGPROXYKIT['client'].
20
+
21
+ Create the client on first use. Django's ``override_settings`` clears
22
+ the cache when entering and leaving an override of ``IMGPROXYKIT``.
23
+ """
24
+ config = get_config()[Settings.client.value]
25
+ # Client takes `base_url` positionally;
26
+ # forward the remaining client options.
27
+ options = {
28
+ name: value
29
+ for name, value in config.items()
30
+ if name != ClientSettings.base_url
31
+ }
32
+ return Client(config[ClientSettings.base_url.value], **options) # type: ignore[call-overload, no-any-return] # pyright: ignore[reportCallIssue, reportArgumentType] # ty: ignore[no-matching-overload]
33
+
34
+
35
+ @receiver(setting_changed)
36
+ def _reset_client(*, setting: str, **kwargs: Any) -> None:
37
+ """Discard the cached client when Django overrides IMGPROXYKIT."""
38
+ if setting == IMGPROXYKIT_SETTINGS:
39
+ get_client.cache_clear()