optivor (Python SDK)
Official Python SDK for Optivor image optimization engine (Django, FastAPI, Flask).
⭐ If you find Optivor useful, please consider giving us a Star on GitHub!
The optivor Python package provides helper methods for building signed and dynamic image transformation URLs.
Installation
pip install optivor
Basic Usage
from optivor import OptivorClient
optivor = OptivorClient(
base_url="https://optivor.example.com",
default_bucket="my-bucket"
)
```python
# Preset-based image optimization (Recommended)
preset_url = optivor.build_preset_url("avatar", "users/john.jpg")
# => https://optivor.example.com/preset/avatar/my-bucket/users/john.jpg
# Generate WebP image URL
url = optivor.build_url(
"photos/landscape.jpg",
width=800,
height=600,
fit="cover",
format="webp"
)
# => https://optivor.example.com/image/my-bucket/photos/landscape.jpg?w=800&h=600&fit=cover&format=webp
Advanced Options
url = optivor.build_url(
"users/avatar.jpg",
width=400,
height=400,
fit="focal",
focal=(0.3, 0.7),
format="avif",
overlay="logo.png",
gravity="bottom_right",
opacity=60,
blur=5.0,
grayscale=True,
pixelate=4
)
Watermark Security & Tamper Protection
To prevent end-users from stripping overlay= or watermark query parameters from public URLs:
- HMAC URL Signing: Generate signed URLs using
security_key. The HMAC-SHA256 signature locks both the path and query parameters (overlay=). Modifying or removing the overlay parameter invalidates the signature, returning403 Forbidden. - Server-Side Presets (
build_preset_url): Useoptivor.build_preset_url('watermarked_thumb', key)to process images using server-side presets defined inoptivor.yaml. The overlay rule stays on the server, leaving no parameters for users to tamper with.
Django Integration Example
# settings.py
OPTIVOR_URL = "https://optivor.example.com"
OPTIVOR_BUCKET = "prod-images"
# templatetags/optivor_tags.py
from django import template
from optivor import OptivorClient
from django.conf import settings
register = template.Library()
optivor = OptivorClient(settings.OPTIVOR_URL, settings.OPTIVOR_BUCKET)
@register.simple_tag
def optivor_url(key, **kwargs):
return optivor.build_url(key, **kwargs)
License
Apache-2.0 © Optivor Team
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optivor-1.2.3.tar.gz.
File metadata
- Download URL: optivor-1.2.3.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc02ee1cd85aed63260765b45f36ed339c94972976a57a80bd4d2d577756ff4c
|
|
| MD5 |
498a44a85fc2192d8ac95ea403b342ba
|
|
| BLAKE2b-256 |
c6e7f5553caffbf1fcdd1ce36e2201dfd48faac5812899895c6a6eeb76252d8b
|
File details
Details for the file optivor-1.2.3-py3-none-any.whl.
File metadata
- Download URL: optivor-1.2.3-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d48ee2a901924a42ff481958f36ba77dcbddfef33e43d2e6b435e93cf68448b0
|
|
| MD5 |
66e77dbb2f2d267b44e6f8221350b9a0
|
|
| BLAKE2b-256 |
a3e668b665f4bcd4d5374d22664e0ae35641d06433b268aec32e091a88f92c74
|