imgproxykit 0.2.1__tar.gz → 0.3.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 (61) hide show
  1. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/PKG-INFO +28 -17
  2. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/README.md +27 -16
  3. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/client.py +22 -9
  4. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/expires.py +4 -6
  5. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_animation_frame_resolution.py +3 -1
  6. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_animation_frames.py +3 -1
  7. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_result_dimension.py +3 -1
  8. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_src_file_size.py +3 -1
  9. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_src_resolution.py +3 -1
  10. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/preset.py +23 -2
  11. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/serialization.py +21 -9
  12. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/signing.py +17 -13
  13. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/transform.py +1 -1
  14. imgproxykit-0.3.0/imgproxykit/types.py +161 -0
  15. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/pyproject.toml +8 -6
  16. imgproxykit-0.2.1/imgproxykit/types.py +0 -95
  17. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/LICENSE +0 -0
  18. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/__init__.py +0 -0
  19. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/internal/__init__.py +0 -0
  20. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/internal/encoding.py +0 -0
  21. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/__init__.py +0 -0
  22. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/auto_rotate.py +0 -0
  23. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/background.py +0 -0
  24. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/base.py +0 -0
  25. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/blur.py +0 -0
  26. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/cache_buster.py +0 -0
  27. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/crop.py +0 -0
  28. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/dpr.py +0 -0
  29. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/enforce_thumbnail.py +0 -0
  30. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/enlarge.py +0 -0
  31. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/extend.py +0 -0
  32. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/extend_aspect_ratio.py +0 -0
  33. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/filename.py +0 -0
  34. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/flip.py +0 -0
  35. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/format.py +0 -0
  36. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/format_quality.py +0 -0
  37. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/gravity.py +0 -0
  38. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/height.py +0 -0
  39. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/keep_copyright.py +0 -0
  40. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/max_bytes.py +0 -0
  41. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/min_height.py +0 -0
  42. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/min_width.py +0 -0
  43. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/padding.py +0 -0
  44. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/pixelate.py +0 -0
  45. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/preserve_hdr.py +0 -0
  46. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/quality.py +0 -0
  47. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/raw.py +0 -0
  48. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/resize.py +0 -0
  49. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/resizing_type.py +0 -0
  50. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/return_attachment.py +0 -0
  51. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/rotate.py +0 -0
  52. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/sharpen.py +0 -0
  53. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/size.py +0 -0
  54. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/skip_processing.py +0 -0
  55. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/strip_color_profile.py +0 -0
  56. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/strip_metadata.py +0 -0
  57. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/trim.py +0 -0
  58. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/watermark.py +0 -0
  59. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/width.py +0 -0
  60. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/options/zoom.py +0 -0
  61. {imgproxykit-0.2.1 → imgproxykit-0.3.0}/imgproxykit/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: imgproxykit
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: A typed Python toolkit for building imgproxy URLs
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -67,22 +67,29 @@ Define a WebP thumbnail once and reuse it across a product catalog:
67
67
  from imgproxykit import Client, Transform
68
68
  from imgproxykit.options import Gravity, Resize
69
69
 
70
- client = Client('https://imgproxy.your-app.com') # Your imgproxy server.
70
+ # Public URL of your imgproxy server.
71
+ client = Client('https://imgproxy.example.com')
71
72
 
72
73
  thumbnail = Transform(
73
- Resize(width=300, height=300, mode='fill'), # Pass option objects.
74
+ Resize(width=300, height=300, mode='fill'), # Pass typed option objects.
74
75
  Gravity(position='sm'), # Let imgproxy choose the crop's focus.
75
- quality=80, # Or scalar, equivalent to Quality(80).
76
+ quality=80, # Or scalar keywords, equivalent to Quality(80).
76
77
  format='webp',
77
78
  )
78
- sources = [
79
- 'https://example.com/products/backpack.jpg',
80
- 'https://example.com/products/sneakers.jpg',
79
+ source_urls = [
80
+ 'https://originals.example.com/products/backpack.jpg',
81
+ 'https://originals.example.com/products/sneakers.jpg',
82
+ ]
83
+ # Reuse one immutable transformation across your catalog.
84
+ thumbnail_urls = [
85
+ client.url(source=source_url, transform=thumbnail)
86
+ for source_url in source_urls
81
87
  ]
82
- thumbnail_urls = [client.url(source, transform=thumbnail) for source in sources]
83
88
  ```
84
89
 
85
- Use these URLs in your images' `src` attributes; imgproxy handles processing.
90
+ Use these URLs in your images' `src` attributes. Building a URL makes no
91
+ network requests: when a browser requests it, imgproxy fetches the original
92
+ image from `originals.example.com` and processes it.
86
93
 
87
94
  Sign URLs and reuse presets configured on your imgproxy server:
88
95
 
@@ -91,21 +98,25 @@ from imgproxykit import Client, Transform
91
98
  from imgproxykit.options import Preset
92
99
 
93
100
  client = Client(
94
- 'https://imgproxy.your-app.com',
95
- key='736563726574', # Example hex credentials; use your server's values.
101
+ 'https://imgproxy.example.com',
102
+ # Replace with your imgproxy server's hex-encoded key and salt.
103
+ key='736563726574',
96
104
  salt='73616c74',
97
105
  )
98
106
 
99
107
  thumbnail = Transform(
100
- Preset(names=('product-card',)),
101
- format='webp',
102
- )
103
- thumbnail_url = client.url(
104
- 'https://example.com/products/backpack.jpg',
105
- transform=product_card,
108
+ Preset('product-card'), # Reuse a preset from your imgproxy server.
109
+ format='webp', # Combine server presets with explicit processing options.
106
110
  )
111
+ source_url = 'https://originals.example.com/products/backpack.jpg'
112
+ # The client signs the URL using your server's key and salt.
113
+ thumbnail_url = client.url(source=source_url, transform=thumbnail)
107
114
  ```
108
115
 
116
+ See the [full documentation](https://imgproxykit.readthedocs.io/en/latest/)
117
+ for client configuration, transformations, and processing options.
118
+ Find published releases on [PyPI](https://pypi.org/project/imgproxykit/).
119
+
109
120
  ## Contributing
110
121
 
111
122
  See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
@@ -39,22 +39,29 @@ Define a WebP thumbnail once and reuse it across a product catalog:
39
39
  from imgproxykit import Client, Transform
40
40
  from imgproxykit.options import Gravity, Resize
41
41
 
42
- client = Client('https://imgproxy.your-app.com') # Your imgproxy server.
42
+ # Public URL of your imgproxy server.
43
+ client = Client('https://imgproxy.example.com')
43
44
 
44
45
  thumbnail = Transform(
45
- Resize(width=300, height=300, mode='fill'), # Pass option objects.
46
+ Resize(width=300, height=300, mode='fill'), # Pass typed option objects.
46
47
  Gravity(position='sm'), # Let imgproxy choose the crop's focus.
47
- quality=80, # Or scalar, equivalent to Quality(80).
48
+ quality=80, # Or scalar keywords, equivalent to Quality(80).
48
49
  format='webp',
49
50
  )
50
- sources = [
51
- 'https://example.com/products/backpack.jpg',
52
- 'https://example.com/products/sneakers.jpg',
51
+ source_urls = [
52
+ 'https://originals.example.com/products/backpack.jpg',
53
+ 'https://originals.example.com/products/sneakers.jpg',
54
+ ]
55
+ # Reuse one immutable transformation across your catalog.
56
+ thumbnail_urls = [
57
+ client.url(source=source_url, transform=thumbnail)
58
+ for source_url in source_urls
53
59
  ]
54
- thumbnail_urls = [client.url(source, transform=thumbnail) for source in sources]
55
60
  ```
56
61
 
57
- Use these URLs in your images' `src` attributes; imgproxy handles processing.
62
+ Use these URLs in your images' `src` attributes. Building a URL makes no
63
+ network requests: when a browser requests it, imgproxy fetches the original
64
+ image from `originals.example.com` and processes it.
58
65
 
59
66
  Sign URLs and reuse presets configured on your imgproxy server:
60
67
 
@@ -63,21 +70,25 @@ from imgproxykit import Client, Transform
63
70
  from imgproxykit.options import Preset
64
71
 
65
72
  client = Client(
66
- 'https://imgproxy.your-app.com',
67
- key='736563726574', # Example hex credentials; use your server's values.
73
+ 'https://imgproxy.example.com',
74
+ # Replace with your imgproxy server's hex-encoded key and salt.
75
+ key='736563726574',
68
76
  salt='73616c74',
69
77
  )
70
78
 
71
79
  thumbnail = Transform(
72
- Preset(names=('product-card',)),
73
- format='webp',
74
- )
75
- thumbnail_url = client.url(
76
- 'https://example.com/products/backpack.jpg',
77
- transform=product_card,
80
+ Preset('product-card'), # Reuse a preset from your imgproxy server.
81
+ format='webp', # Combine server presets with explicit processing options.
78
82
  )
83
+ source_url = 'https://originals.example.com/products/backpack.jpg'
84
+ # The client signs the URL using your server's key and salt.
85
+ thumbnail_url = client.url(source=source_url, transform=thumbnail)
79
86
  ```
80
87
 
88
+ See the [full documentation](https://imgproxykit.readthedocs.io/en/latest/)
89
+ for client configuration, transformations, and processing options.
90
+ Find published releases on [PyPI](https://pypi.org/project/imgproxykit/).
91
+
81
92
  ## Contributing
82
93
 
83
94
  See the [contributing guide](CONTRIBUTING.md) for development setup and checks.
@@ -43,6 +43,7 @@ class Client:
43
43
  key: None = None,
44
44
  salt: None = None,
45
45
  unsigned_signature: str = 'unsafe',
46
+ arguments_separator: str = ':',
46
47
  ) -> None: ...
47
48
 
48
49
  @overload
@@ -54,9 +55,10 @@ class Client:
54
55
  key: str,
55
56
  salt: str,
56
57
  signature_size: int = 32,
58
+ arguments_separator: str = ':',
57
59
  ) -> None: ...
58
60
 
59
- def __init__(
61
+ def __init__( # noqa: WPS211
60
62
  self,
61
63
  base_url: str,
62
64
  /,
@@ -65,6 +67,7 @@ class Client:
65
67
  salt: str | None = None,
66
68
  signature_size: int = 32,
67
69
  unsigned_signature: str = 'unsafe',
70
+ arguments_separator: str = ':',
68
71
  ) -> None:
69
72
  """
70
73
  Configure the imgproxy address and create the client components.
@@ -82,11 +85,19 @@ class Client:
82
85
  salt: Nonempty hex-encoded signing salt matching the server.
83
86
  Supply together with ``key``; ``None`` selects unsigned mode.
84
87
  signature_size: Positive digest byte count to encode. Must match
85
- the server's ``IMGPROXY_SIGNATURE_SIZE``. Defaults to ``32``.
88
+ the server's `IMGPROXY_SIGNATURE_SIZE
89
+ <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
90
+ Defaults to ``32``.
86
91
  Values of 32 or more use the full digest.
87
92
  unsigned_signature: URL marker used when key and salt are omitted.
88
93
  Defaults to ``'unsafe'``. With server signing enabled,
89
- configure this marker in ``IMGPROXY_TRUSTED_SIGNATURES``.
94
+ configure this marker in `IMGPROXY_TRUSTED_SIGNATURES
95
+ <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
96
+ arguments_separator: Separator between processing option names
97
+ and their arguments. Must match the server's
98
+ `IMGPROXY_ARGUMENTS_SEPARATOR
99
+ <https://docs.imgproxy.net/latest/configuration/options#miscellaneous>`__.
100
+ Defaults to ``':'``.
90
101
 
91
102
  Raises:
92
103
  ValueError: With the default signer, if only one signing
@@ -97,19 +108,22 @@ class Client:
97
108
  Create an unsigned client:
98
109
 
99
110
  >>> from imgproxykit import Client
100
- >>> client = Client('https://images.example.com')
111
+ >>> client = Client('https://imgproxy.example.com')
101
112
 
102
113
  Create a signed client with example credentials:
103
114
 
104
115
  >>> client = Client(
105
- ... 'https://images.example.com',
116
+ ... 'https://imgproxy.example.com',
106
117
  ... key='736563726574',
107
118
  ... salt='73616c74',
108
119
  ... )
109
120
 
110
121
  """
111
- self._base_url = base_url
112
- self._path_serializer = self.path_serializer_cls()
122
+ # Prepare `base_url` only once pre instance
123
+ self._base_url = base_url.rstrip('/')
124
+ self._path_serializer = self.path_serializer_cls(
125
+ arguments_separator=arguments_separator,
126
+ )
113
127
  self._url_signer = self.url_signer_cls(
114
128
  key=key,
115
129
  salt=salt,
@@ -149,5 +163,4 @@ class Client:
149
163
  """
150
164
  path = self._path_serializer(source, transform=transform)
151
165
  signature = self._url_signer(path)
152
- base_url = self._base_url.rstrip('/')
153
- return f'{base_url}/{signature}{path}'
166
+ return f'{self._base_url}/{signature}{path}'
@@ -15,15 +15,13 @@ class Expires(ScalarOption[int]):
15
15
  Attributes:
16
16
  value: Expiration time as a Unix timestamp in seconds.
17
17
 
18
- Usage:
19
-
20
- >>> option = Expires(300)
21
- >>> option.arguments
22
- (300,)
23
-
24
18
  See `imgproxy expires
25
19
  <https://docs.imgproxy.net/usage/processing#expires>`_.
26
20
 
27
21
  """
28
22
 
23
+ # TODO: Accept timezone-aware datetime objects and convert them to Unix
24
+ # timestamps. Consider timedelta for relative expiry, resolved once at
25
+ # construction so reusing a Transform produces a stable URL. Define how
26
+ # naive datetimes and subsecond precision are handled.
29
27
  name: ClassVar[OptionType] = 'expires'
@@ -11,7 +11,9 @@ class MaxAnimationFrameResolution(ScalarOption[float]):
11
11
  Override frame megapixel limit; requires ALLOW_SECURITY_OPTIONS.
12
12
 
13
13
  Overrides the corresponding server limit for this request. Requires
14
- ``IMGPROXY_ALLOW_SECURITY_OPTIONS=true`` on the imgproxy server.
14
+ `IMGPROXY_ALLOW_SECURITY_OPTIONS
15
+ <https://docs.imgproxy.net/latest/configuration/options#security>`__
16
+ set to ``true`` on the imgproxy server.
15
17
 
16
18
  Attributes:
17
19
  value: Animation frame resolution limit in megapixels.
@@ -11,7 +11,9 @@ class MaxAnimationFrames(ScalarOption[int]):
11
11
  Override animation frame limit; requires ALLOW_SECURITY_OPTIONS.
12
12
 
13
13
  Overrides the corresponding server limit for this request. Requires
14
- ``IMGPROXY_ALLOW_SECURITY_OPTIONS=true`` on the imgproxy server.
14
+ `IMGPROXY_ALLOW_SECURITY_OPTIONS
15
+ <https://docs.imgproxy.net/latest/configuration/options#security>`__
16
+ set to ``true`` on the imgproxy server.
15
17
 
16
18
  Attributes:
17
19
  value: Maximum number of animation frames.
@@ -11,7 +11,9 @@ class MaxResultDimension(ScalarOption[int]):
11
11
  Override output dimension limit; requires ALLOW_SECURITY_OPTIONS.
12
12
 
13
13
  Overrides the corresponding server limit for this request. Requires
14
- ``IMGPROXY_ALLOW_SECURITY_OPTIONS=true`` on the imgproxy server.
14
+ `IMGPROXY_ALLOW_SECURITY_OPTIONS
15
+ <https://docs.imgproxy.net/latest/configuration/options#security>`__
16
+ set to ``true`` on the imgproxy server.
15
17
 
16
18
  Attributes:
17
19
  value: Maximum resulting width or height in pixels.
@@ -11,7 +11,9 @@ class MaxSrcFileSize(ScalarOption[int]):
11
11
  Override source byte limit; requires ALLOW_SECURITY_OPTIONS.
12
12
 
13
13
  Overrides the corresponding server limit for this request. Requires
14
- ``IMGPROXY_ALLOW_SECURITY_OPTIONS=true`` on the imgproxy server.
14
+ `IMGPROXY_ALLOW_SECURITY_OPTIONS
15
+ <https://docs.imgproxy.net/latest/configuration/options#security>`__
16
+ set to ``true`` on the imgproxy server.
15
17
 
16
18
  Attributes:
17
19
  value: Source file size limit in bytes.
@@ -11,7 +11,9 @@ class MaxSrcResolution(ScalarOption[float]):
11
11
  Override source megapixel limit; requires ALLOW_SECURITY_OPTIONS.
12
12
 
13
13
  Overrides the corresponding server limit for this request. Requires
14
- ``IMGPROXY_ALLOW_SECURITY_OPTIONS=true`` on the imgproxy server.
14
+ `IMGPROXY_ALLOW_SECURITY_OPTIONS
15
+ <https://docs.imgproxy.net/latest/configuration/options#security>`__
16
+ set to ``true`` on the imgproxy server.
15
17
 
16
18
  Attributes:
17
19
  value: Source resolution limit in megapixels.
@@ -5,7 +5,7 @@ from imgproxykit.options.base import Option
5
5
  from imgproxykit.types import Argument, OptionType
6
6
 
7
7
 
8
- @dataclass(frozen=True, slots=True, kw_only=True)
8
+ @dataclass(frozen=True, slots=True, init=False)
9
9
  class Preset(Option):
10
10
  """
11
11
  Reference named presets configured on the imgproxy server.
@@ -19,7 +19,7 @@ class Preset(Option):
19
19
 
20
20
  Usage:
21
21
 
22
- >>> option = Preset(names=('thumbnail', 'watermarked'))
22
+ >>> option = Preset('thumbnail', 'watermarked')
23
23
  >>> option.arguments
24
24
  ('thumbnail', 'watermarked')
25
25
 
@@ -32,6 +32,27 @@ class Preset(Option):
32
32
 
33
33
  name: ClassVar[OptionType] = 'preset'
34
34
 
35
+ def __init__(self, *names: str) -> None:
36
+ """
37
+ Store preset names in their supplied order.
38
+
39
+ Args:
40
+ *names: Server preset names in imgproxy protocol order.
41
+
42
+ Examples:
43
+ Reference a single preset, then several in order:
44
+
45
+ >>> Preset('thumbnail').arguments
46
+ ('thumbnail',)
47
+ >>> Preset('thumbnail', 'watermarked').arguments
48
+ ('thumbnail', 'watermarked')
49
+
50
+ """
51
+ # Keep variadic names while initializing a frozen dataclass.
52
+ # Bypassing __setattr__ is safe until initialization is finished.
53
+ object.__setattr__(self, 'names', names)
54
+ self.validate()
55
+
35
56
  @property
36
57
  @override
37
58
  def arguments(self) -> tuple[Argument, ...]:
@@ -21,10 +21,22 @@ class PathSerializer:
21
21
 
22
22
  """
23
23
 
24
- __slots__ = ()
24
+ __slots__ = ('_arguments_separator',)
25
25
 
26
- # TODO: Support source_url_encryption_key for source URL encryption (Pro).
27
26
  # TODO: Support the plain option for unencoded source URLs.
27
+ def __init__(self, *, arguments_separator: str) -> None:
28
+ """
29
+ Configure processing option serialization.
30
+
31
+ Args:
32
+ arguments_separator: Separator between processing option names
33
+ and their arguments. Must match the server's
34
+ `IMGPROXY_ARGUMENTS_SEPARATOR
35
+ <https://docs.imgproxy.net/latest/configuration/options#miscellaneous>`__.
36
+
37
+ """
38
+ self._arguments_separator = arguments_separator
39
+
28
40
  def __call__(
29
41
  self,
30
42
  source: str,
@@ -34,8 +46,8 @@ class PathSerializer:
34
46
  """
35
47
  Build an unsigned path using processing options and preset references.
36
48
 
37
- Serialize each option as a colon-separated segment before the encoded
38
- source. Output format options are included as processing segments.
49
+ Serialize each option using the configured arguments separator before
50
+ the encoded source. Output formats are included as processing segments.
39
51
  Omitted processing parameters are left to the server.
40
52
 
41
53
  Args:
@@ -55,7 +67,7 @@ class PathSerializer:
55
67
  >>> from imgproxykit import Transform
56
68
  >>> from imgproxykit.serialization import PathSerializer
57
69
  >>> from imgproxykit.options import Resize
58
- >>> serializer = PathSerializer()
70
+ >>> serializer = PathSerializer(arguments_separator=':')
59
71
  >>> thumbnail = Transform(
60
72
  ... Resize(width=96, height=96, mode='fill'),
61
73
  ... format='webp',
@@ -74,9 +86,8 @@ class PathSerializer:
74
86
  )
75
87
  return '/'.join(('', *options, encode_base64(source)))
76
88
 
77
- @classmethod
78
89
  def _serialize_segment(
79
- cls,
90
+ self,
80
91
  name: str,
81
92
  arguments: tuple[Argument, ...],
82
93
  ) -> str:
@@ -93,8 +104,9 @@ class PathSerializer:
93
104
  end = len(arguments)
94
105
  while end and arguments[end - 1] is None:
95
106
  end -= 1
96
- serialized = map(cls._serialize_argument, arguments[:end])
97
- return ':'.join((name, *serialized))
107
+
108
+ serialized = map(self._serialize_argument, arguments[:end])
109
+ return self._arguments_separator.join((name, *serialized))
98
110
 
99
111
  @classmethod
100
112
  def _serialize_argument(cls, value: Argument) -> str:
@@ -15,7 +15,8 @@ class UrlSigner:
15
15
 
16
16
  Used by :class:`~imgproxykit.Client` after path construction.
17
17
  Credentials are decoded once during initialization and reused for
18
- subsequent signatures. Omitting both credentials enables unsigned mode.
18
+ subsequent signatures. Passing ``None`` for both credentials enables
19
+ unsigned mode.
19
20
 
20
21
  Subclass this signer and override :meth:`__call__` to customize signing.
21
22
  Set the subclass on :attr:`imgproxykit.Client.url_signer_cls` to use it
@@ -32,16 +33,16 @@ class UrlSigner:
32
33
  def __init__(
33
34
  self,
34
35
  *,
35
- key: str | None = None,
36
- salt: str | None = None,
37
- signature_size: int = 32,
38
- unsigned_signature: str = 'unsafe',
36
+ key: str | None,
37
+ salt: str | None,
38
+ signature_size: int,
39
+ unsigned_signature: str,
39
40
  ) -> None:
40
41
  """
41
42
  Configure signing credentials or enable unsigned mode.
42
43
 
43
- Supply both ``key`` and ``salt`` to generate signatures. Omit both to
44
- return the configured unsigned marker (``unsafe`` by default).
44
+ Supply both ``key`` and ``salt`` to generate signatures. Pass ``None``
45
+ for both to return the configured unsigned marker.
45
46
  The server must accept unsigned requests or trust that marker.
46
47
 
47
48
  Args:
@@ -50,11 +51,14 @@ class UrlSigner:
50
51
  salt: Nonempty hex-encoded signing salt matching the server.
51
52
  Supply together with ``key``; ``None`` selects unsigned mode.
52
53
  signature_size: Positive digest byte count to encode. Must match
53
- the server's ``IMGPROXY_SIGNATURE_SIZE``. Defaults to ``32``.
54
+ the server's `IMGPROXY_SIGNATURE_SIZE
55
+ <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
54
56
  Values of 32 or more use the full digest.
55
- unsigned_signature: URL marker used when key and salt are omitted.
56
- Defaults to ``'unsafe'``. With server signing enabled,
57
- configure this marker in ``IMGPROXY_TRUSTED_SIGNATURES``.
57
+ unsigned_signature: URL marker used when key and salt are both
58
+ ``None``.
59
+ With server signing enabled, configure this marker
60
+ in `IMGPROXY_TRUSTED_SIGNATURES
61
+ <https://docs.imgproxy.net/latest/configuration/options#url-signature>`__.
58
62
 
59
63
  Raises:
60
64
  ValueError: If only one signing credential is supplied, either
@@ -72,7 +76,7 @@ class UrlSigner:
72
76
  self._unsigned_signature = unsigned_signature
73
77
  self._signature_size = signature_size
74
78
 
75
- # Omitting both credentials selects unsigned mode.
79
+ # Passing None for both credentials selects unsigned mode.
76
80
  if key is None or salt is None:
77
81
  self._credentials = None
78
82
  return
@@ -96,7 +100,7 @@ class UrlSigner:
96
100
 
97
101
  Returns:
98
102
  URL-safe Base64 signature without padding, or the unsigned
99
- marker when signing credentials were omitted.
103
+ marker when both signing credentials are ``None``.
100
104
 
101
105
  """
102
106
  if self._credentials is None:
@@ -43,7 +43,7 @@ class ScalarOptions(TypedDict, total=False, closed=True):
43
43
  width: int
44
44
 
45
45
 
46
- @dataclass(frozen=True, slots=True)
46
+ @dataclass(frozen=True, slots=True, init=False)
47
47
  class Transform:
48
48
  """
49
49
  Define reusable image processing options.
@@ -0,0 +1,161 @@
1
+ from typing import Literal
2
+
3
+ type Argument = str | int | float | bool | None
4
+ """
5
+ Scalar value accepted in an option's positional arguments.
6
+
7
+ Values in :attr:`~imgproxykit.options.Option.arguments`. Booleans become
8
+ ``1`` or ``0``. ``None`` leaves an empty argument position; trailing
9
+ ``None`` values are omitted by the default serializer.
10
+
11
+ See `imgproxy processing options
12
+ <https://docs.imgproxy.net/usage/processing#processing-options>`_.
13
+ """
14
+
15
+ type FormatType = Literal[
16
+ 'png',
17
+ 'jpg',
18
+ 'jxl',
19
+ 'webp',
20
+ 'avif',
21
+ 'gif',
22
+ 'ico',
23
+ 'svg',
24
+ 'heic',
25
+ 'bmp',
26
+ 'tiff',
27
+ ]
28
+ """
29
+ Image format identifiers accepted by imgproxykit.
30
+
31
+ Formats for :class:`~imgproxykit.options.Format`,
32
+ :class:`~imgproxykit.options.FormatQuality`, and the ``format`` keyword
33
+ of :class:`~imgproxykit.Transform`. For example, use ``jpg`` for JPEG
34
+ and ``jxl`` for JPEG XL.
35
+
36
+ An identifier in this type does not guarantee output support on your
37
+ server. Supported input and output formats depend on the imgproxy build;
38
+ SVG output has additional restrictions.
39
+
40
+ See `imgproxy format
41
+ <https://docs.imgproxy.net/usage/processing#format>`_ and the
42
+ `image formats support matrix
43
+ <https://docs.imgproxy.net/image_formats_support>`_.
44
+ """
45
+
46
+ type OptionType = Literal[
47
+ 'format',
48
+ 'preset',
49
+ 'width',
50
+ 'height',
51
+ 'min-width',
52
+ 'min-height',
53
+ 'resizing_type',
54
+ 'enlarge',
55
+ 'auto_rotate',
56
+ 'rotate',
57
+ 'blur',
58
+ 'sharpen',
59
+ 'pixelate',
60
+ 'strip_metadata',
61
+ 'keep_copyright',
62
+ 'strip_color_profile',
63
+ 'preserve_hdr',
64
+ 'enforce_thumbnail',
65
+ 'max_bytes',
66
+ 'raw',
67
+ 'expires',
68
+ 'return_attachment',
69
+ 'max_src_resolution',
70
+ 'max_src_file_size',
71
+ 'max_animation_frames',
72
+ 'max_animation_frame_resolution',
73
+ 'max_result_dimension',
74
+ 'size',
75
+ 'zoom',
76
+ 'extend',
77
+ 'extend_aspect_ratio',
78
+ 'crop',
79
+ 'trim',
80
+ 'padding',
81
+ 'flip',
82
+ 'background',
83
+ 'format_quality',
84
+ 'skip_processing',
85
+ 'filename',
86
+ 'cachebuster',
87
+ 'resize',
88
+ 'gravity',
89
+ 'dpr',
90
+ 'quality',
91
+ 'watermark',
92
+ ]
93
+ """
94
+ Processing option names represented by imgproxykit's built-in options.
95
+
96
+ Names in :attr:`~imgproxykit.options.Option.name` identify URL segments.
97
+ These are protocol names; scalar keywords in
98
+ :class:`~imgproxykit.Transform` replace hyphens with underscores.
99
+ For example, ``min-width`` corresponds to ``min_width``.
100
+
101
+ This type describes the library's supported names, rather than every
102
+ option available in every imgproxy version or edition.
103
+
104
+ See `imgproxy processing options
105
+ <https://docs.imgproxy.net/usage/processing#processing-options>`_.
106
+ """
107
+
108
+ type WatermarkPosition = Literal[
109
+ 'ce',
110
+ 'no',
111
+ 'so',
112
+ 'ea',
113
+ 'we',
114
+ 'noea',
115
+ 'nowe',
116
+ 'soea',
117
+ 'sowe',
118
+ 're',
119
+ ]
120
+ """
121
+ Placement codes for :class:`~imgproxykit.options.Watermark`.
122
+
123
+ See `imgproxy watermark
124
+ <https://docs.imgproxy.net/usage/processing#watermark>`_.
125
+ """
126
+
127
+ type ResizeType = Literal[
128
+ 'fit',
129
+ 'fill',
130
+ 'fill-down',
131
+ 'force',
132
+ 'auto',
133
+ ]
134
+ """
135
+ Resizing modes for :class:`~imgproxykit.options.Resize` and
136
+ :class:`~imgproxykit.options.ResizingType`.
137
+
138
+ See `imgproxy resizing type
139
+ <https://docs.imgproxy.net/usage/processing#resizing-type>`_.
140
+ """
141
+
142
+ type Position = Literal[
143
+ 'no',
144
+ 'so',
145
+ 'ea',
146
+ 'we',
147
+ 'noea',
148
+ 'nowe',
149
+ 'soea',
150
+ 'sowe',
151
+ 'ce',
152
+ 'sm',
153
+ 'fp',
154
+ ]
155
+ """
156
+ Gravity codes for :class:`~imgproxykit.options.Gravity` and
157
+ :class:`~imgproxykit.options.Crop`.
158
+
159
+ See `imgproxy gravity
160
+ <https://docs.imgproxy.net/usage/processing#gravity>`_.
161
+ """
@@ -5,7 +5,7 @@ requires = [ "poetry-core>=2" ]
5
5
 
6
6
  [project]
7
7
  name = "imgproxykit"
8
- version = "0.2.1"
8
+ version = "0.3.0"
9
9
  description = "A typed Python toolkit for building imgproxy URLs"
10
10
  readme = "README.md"
11
11
  keywords = [
@@ -52,7 +52,7 @@ mypy = "^2.4"
52
52
  pyrefly = ">=1,<2"
53
53
  pyright = ">=1.1,<2"
54
54
  # TODO: relax the pin after a stable `ty` release:
55
- ty = "==0.0.86"
55
+ ty = "==0.0.87"
56
56
  pytest = "^9.1"
57
57
  pytest-cov = "^7.1"
58
58
  pytest-randomly = "^5.0"
@@ -71,7 +71,8 @@ optional = true
71
71
  myst-parser = "^5.1"
72
72
  sphinx = "^9.0"
73
73
  sphinx-autodoc-typehints = "^3.13"
74
- shibuya = "^2026.7"
74
+ sphinx-immaterial = "^0.13"
75
+ sphinx-iconify = "^0.3"
75
76
 
76
77
 
77
78
  [tool.ruff]
@@ -217,7 +218,7 @@ strict = true
217
218
 
218
219
 
219
220
  [tool.pyrefly]
220
- project-includes = [ "imgproxykit", "tests" ]
221
+ project-includes = [ "imgproxykit", "tests", "docs/examples" ]
221
222
  min-severity = "warn"
222
223
  preset = "strict"
223
224
 
@@ -233,7 +234,7 @@ pythonVersion = "3.12"
233
234
  venv = ".venv"
234
235
  venvPath = "."
235
236
  typeCheckingMode = "strict"
236
- include = [ "imgproxykit", "tests" ]
237
+ include = [ "imgproxykit", "tests", "docs/examples" ]
237
238
  enableTypeIgnoreComments = false
238
239
  reportUnnecessaryTypeIgnoreComment = "error"
239
240
 
@@ -246,7 +247,7 @@ reportPrivateUsage = false
246
247
 
247
248
  [tool.ty.src]
248
249
  # Docs: https://docs.astral.sh/ty/reference/configuration
249
- include = [ "imgproxykit", "tests" ]
250
+ include = [ "imgproxykit", "tests", "docs/examples" ]
250
251
 
251
252
  [tool.ty.analysis]
252
253
  strict-literal-narrowing = true
@@ -269,6 +270,7 @@ addopts = [
269
270
  # Coverage:
270
271
  "--cov=imgproxykit",
271
272
  "--cov=tests",
273
+ "--cov=docs/examples",
272
274
  "--cov-report=term-missing:skip-covered",
273
275
  "--cov-report=html",
274
276
  "--cov-report=xml",
@@ -1,95 +0,0 @@
1
- from typing import Literal
2
-
3
- type Argument = str | int | float | bool | None
4
- type FormatType = Literal[
5
- 'png',
6
- 'jpg',
7
- 'jxl',
8
- 'webp',
9
- 'avif',
10
- 'gif',
11
- 'ico',
12
- 'svg',
13
- 'heic',
14
- 'bmp',
15
- 'tiff',
16
- ]
17
- type OptionType = Literal[
18
- 'format',
19
- 'preset',
20
- 'width',
21
- 'height',
22
- 'min-width',
23
- 'min-height',
24
- 'resizing_type',
25
- 'enlarge',
26
- 'auto_rotate',
27
- 'rotate',
28
- 'blur',
29
- 'sharpen',
30
- 'pixelate',
31
- 'strip_metadata',
32
- 'keep_copyright',
33
- 'strip_color_profile',
34
- 'preserve_hdr',
35
- 'enforce_thumbnail',
36
- 'max_bytes',
37
- 'raw',
38
- 'expires',
39
- 'return_attachment',
40
- 'max_src_resolution',
41
- 'max_src_file_size',
42
- 'max_animation_frames',
43
- 'max_animation_frame_resolution',
44
- 'max_result_dimension',
45
- 'size',
46
- 'zoom',
47
- 'extend',
48
- 'extend_aspect_ratio',
49
- 'crop',
50
- 'trim',
51
- 'padding',
52
- 'flip',
53
- 'background',
54
- 'format_quality',
55
- 'skip_processing',
56
- 'filename',
57
- 'cachebuster',
58
- 'resize',
59
- 'gravity',
60
- 'dpr',
61
- 'quality',
62
- 'watermark',
63
- ]
64
- type WatermarkPosition = Literal[
65
- 'ce',
66
- 'no',
67
- 'so',
68
- 'ea',
69
- 'we',
70
- 'noea',
71
- 'nowe',
72
- 'soea',
73
- 'sowe',
74
- 're',
75
- ]
76
- type ResizeType = Literal[
77
- 'fit',
78
- 'fill',
79
- 'fill-down',
80
- 'force',
81
- 'auto',
82
- ]
83
- type Position = Literal[
84
- 'no',
85
- 'so',
86
- 'ea',
87
- 'we',
88
- 'noea',
89
- 'nowe',
90
- 'soea',
91
- 'sowe',
92
- 'ce',
93
- 'sm',
94
- 'fp',
95
- ]
File without changes