optivor 1.2.0__py3-none-any.whl
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.
optivor/__init__.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from urllib.parse import urlencode, rstrip
|
|
2
|
+
|
|
3
|
+
class OptivorClient:
|
|
4
|
+
def __init__(self, base_url: str = "http://localhost:8080", default_bucket: str = ""):
|
|
5
|
+
self.base_url = base_url.rstrip("/")
|
|
6
|
+
self.default_bucket = default_bucket
|
|
7
|
+
|
|
8
|
+
def build_url(self, key: str, **params) -> str:
|
|
9
|
+
clean_key = key.lstrip("/")
|
|
10
|
+
if self.default_bucket and "/" not in clean_key:
|
|
11
|
+
full_path = f"{self.default_bucket}/{clean_key}"
|
|
12
|
+
else:
|
|
13
|
+
full_path = clean_key
|
|
14
|
+
|
|
15
|
+
query = {}
|
|
16
|
+
if "width" in params or "w" in params:
|
|
17
|
+
query["w"] = params.get("width") or params.get("w")
|
|
18
|
+
if "height" in params or "h" in params:
|
|
19
|
+
query["h"] = params.get("height") or params.get("h")
|
|
20
|
+
if "fit" in params:
|
|
21
|
+
query["fit"] = params["fit"]
|
|
22
|
+
if "format" in params:
|
|
23
|
+
query["format"] = params["format"]
|
|
24
|
+
if "focal" in params:
|
|
25
|
+
focal = params["focal"]
|
|
26
|
+
query["focal"] = ",".join(map(str, focal)) if isinstance(focal, (list, tuple)) else str(focal)
|
|
27
|
+
if "overlay" in params:
|
|
28
|
+
query["overlay"] = params["overlay"]
|
|
29
|
+
if "gravity" in params:
|
|
30
|
+
query["gravity"] = params["gravity"]
|
|
31
|
+
if "opacity" in params:
|
|
32
|
+
query["opacity"] = params["opacity"]
|
|
33
|
+
if "blur" in params:
|
|
34
|
+
query["blur"] = params["blur"]
|
|
35
|
+
if params.get("grayscale"):
|
|
36
|
+
query["grayscale"] = "true"
|
|
37
|
+
if "pixelate" in params:
|
|
38
|
+
query["pixelate"] = params["pixelate"]
|
|
39
|
+
|
|
40
|
+
q_str = urlencode(query)
|
|
41
|
+
return f"{self.base_url}/image/{full_path}{'?' + q_str if q_str else ''}"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: optivor
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Official Python SDK for Optivor image optimization engine (Django / FastAPI support)
|
|
5
|
+
Author: Optivor Team
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# `optivor` (Python SDK)
|
|
10
|
+
|
|
11
|
+
> Official Python SDK for [Optivor](https://github.com/optivor/optivor) image optimization engine (Django, FastAPI, Flask).
|
|
12
|
+
|
|
13
|
+
[](https://pypi.org/project/optivor/)
|
|
14
|
+
[](LICENSE)
|
|
15
|
+
|
|
16
|
+
The `optivor` Python package provides helper methods for building signed and dynamic image transformation URLs.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install optivor
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Basic Usage
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from optivor import OptivorClient
|
|
32
|
+
|
|
33
|
+
optivor = OptivorClient(
|
|
34
|
+
base_url="https://optivor.example.com",
|
|
35
|
+
default_bucket="my-bucket"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# Generate WebP image URL
|
|
39
|
+
url = optivor.build_url(
|
|
40
|
+
"photos/landscape.jpg",
|
|
41
|
+
width=800,
|
|
42
|
+
height=600,
|
|
43
|
+
fit="cover",
|
|
44
|
+
format="webp"
|
|
45
|
+
)
|
|
46
|
+
# => https://optivor.example.com/image/my-bucket/photos/landscape.jpg?w=800&h=600&fit=cover&format=webp
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Advanced Options
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
url = optivor.build_url(
|
|
55
|
+
"users/avatar.jpg",
|
|
56
|
+
width=400,
|
|
57
|
+
height=400,
|
|
58
|
+
fit="focal",
|
|
59
|
+
focal=(0.3, 0.7),
|
|
60
|
+
format="avif",
|
|
61
|
+
overlay="logo.png",
|
|
62
|
+
gravity="bottom_right",
|
|
63
|
+
opacity=60,
|
|
64
|
+
blur=5.0,
|
|
65
|
+
grayscale=True,
|
|
66
|
+
pixelate=4
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Django Integration Example
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
# settings.py
|
|
76
|
+
OPTIVOR_URL = "https://optivor.example.com"
|
|
77
|
+
OPTIVOR_BUCKET = "prod-images"
|
|
78
|
+
|
|
79
|
+
# templatetags/optivor_tags.py
|
|
80
|
+
from django import template
|
|
81
|
+
from optivor import OptivorClient
|
|
82
|
+
from django.conf import settings
|
|
83
|
+
|
|
84
|
+
register = template.Library()
|
|
85
|
+
optivor = OptivorClient(settings.OPTIVOR_URL, settings.OPTIVOR_BUCKET)
|
|
86
|
+
|
|
87
|
+
@register.simple_tag
|
|
88
|
+
def optivor_url(key, **kwargs):
|
|
89
|
+
return optivor.build_url(key, **kwargs)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
Apache-2.0 © Optivor Team
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
optivor/__init__.py,sha256=0aZwnDtGGK3crjezvUmI668bBR9WPs9R5Y7YVyn_7dc,1656
|
|
2
|
+
optivor-1.2.0.dist-info/METADATA,sha256=wAH1eDCEomoJAoaaLT99ZuODJeihLLdkjB09nFnYPcU,1959
|
|
3
|
+
optivor-1.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
4
|
+
optivor-1.2.0.dist-info/top_level.txt,sha256=g8rcjnkO73rYRKZpUw8fJ8gMkP3QvEens3O1i1vA9Og,8
|
|
5
|
+
optivor-1.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
optivor
|