Toilmore Python API
Installing
pip install toilmore-sdk
How to use
Simplifies using the toilmore API by wrapping the request state machine. To optimize an image, all you need is a valid API token, and domain. See here how to get them.
Using the light API
import os
import asyncio
from toilmoresdk import (
LIGHT_API,
Toilmore,
)
from toilmoresdk.submit_machine import (
OptimizationResponseStatus,
RejectionNoticeToHumanEnum,
)
from toilmoresdk.stream_helpers import store_file_content
from toilmoresdk.api_config import ApiConfig
from toilmoresdk.constants import PrecursorEnum
from toilmoresdk import constants
config = ApiConfig(
# LIGHT_API contains our light api endpoint.
api_endpoint=LIGHT_API,
# Use a valid API token below:
api_token='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
# Use a valid domain below, as received when
# you created the token.
domain='YYYYYYYYYYYYYYYYYYYYYYYYYY'
)
toilmore = Toilmore(config)
loop = asyncio.get_event_loop()
image_path = "./my_image.jpg"
precursor = PrecursorEnum.WEBP0
r = loop.run_until_complete(
toilmore.optimize(image_path, precursor)
)
if r.status == OptimizationResponseStatus.FAILURE:
rejection_notice = r.rejection_notice
rejection_notice_enum = rejection_notice.rejection_notice
human_readable = RejectionNoticeToHumanEnum[
rejection_notice_enum.name
].value
print(
f'Failure: {human_readable} '
f'rejection_notice: { rejection_notice.rejection_notice}, '
f'inner_error: {rejection_notice.inner_error}'
)
elif r.status == OptimizationResponseStatus.SUCCESS:
base_filename, file_extension = os.path.splitext(image_path)
output_filename = '{}{}'.format(
base_filename,
constants.PrecursorToExtensionEnum[precursor.name].value
)
output_dir = os.path.join(
os.path.abspath(os.path.dirname(image_path)),
output_filename
)
loop.run_until_complete(
store_file_content(
r.response_stream,
output_dir
)
)
print('Optimized image stored at: ', output_dir)
Using the Lux API
import os
import asyncio
from toilmoresdk import (
LUX_API,
Toilmore,
)
from toilmoresdk.submit_machine import (
OptimizationResponseStatus,
RejectionNoticeToHumanEnum,
)
from toilmoresdk.stream_helpers import store_file_content
from toilmoresdk.api_config import ApiConfig
from toilmoresdk.constants import PrecursorEnum
from toilmoresdk import constants
config = ApiConfig(
# LIGHT_API contains our light api endpoint.
api_endpoint=LUX_API,
# Use a valid API token below:
api_token='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
# Use a valid domain below, as received when
# you created the token.
domain='YYYYYYYYYYYYYYYYYYYYYYYYYY'
)
toilmore = Toilmore(config)
loop = asyncio.get_event_loop()
image_path = "./my_image.jpg"
precursor = PrecursorEnum.WEBP0
adjustments = {
"shifter": {
"steps": [
{
"scale-to": {
"width": 90
}
}
]
},
"encoder": {
"quality-measure": "fsim-c",
"qual-threshold": 0.90
}
}
r = loop.run_until_complete(
toilmore.optimize(image_path, precursor, adjustments)
)
if r.status == OptimizationResponseStatus.FAILURE:
rejection_notice = r.rejection_notice
rejection_notice_enum = rejection_notice.rejection_notice
human_readable = RejectionNoticeToHumanEnum[
rejection_notice_enum.name
].value
print(
f'Failure: {human_readable} '
f'rejection_notice: { rejection_notice.rejection_notice}, '
f'inner_error: {rejection_notice.inner_error}'
)
elif r.status == OptimizationResponseStatus.SUCCESS:
base_filename, file_extension = os.path.splitext(image_path)
output_filename = '{}{}'.format(
base_filename,
constants.PrecursorToExtensionEnum[precursor.name].value
)
output_dir = os.path.join(
os.path.abspath(os.path.dirname(image_path)),
output_filename
)
loop.run_until_complete(
store_file_content(
r.response_stream,
output_dir
)
)
print('Optimized image stored at: ', output_dir)
To know more about the lux's adjustments, please take a look to the following doc:
- https://demo.pixellena.com/adjustments/
- https://pixellena.com/docs/quality-measures/
- https://pixellena.com/docs/enhance/
- https://pixellena.com/docs/master/
- https://pixellena.com/docs/encoder/
Both the light and the lux API are supported as you could see above.
Metadata
Release files for toilmore-sdk 0.2.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toilmore-sdk-0.2.7.tar.gz | 20.7 kB | Without provenance | Details for toilmore-sdk-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toilmore_sdk-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for toilmore_sdk-0.2.7-py3-none-any.whl |
Total release size: 47.5 kB
Release files / toilmore-sdk-0.2.7.tar.gz
| Download URL | toilmore-sdk-0.2.7.tar.gz |
|---|---|
| Size | 20.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
180c730a3545da7853746872717211af49fb8698cf2551961436e21a4f8aac0a
|
|
BLAKE2b-256 checksum How to use checksums |
65043c9a823c1d294755303119425ec16f75ede3894e3057a9db7c5d8aaf1c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.26.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5
|
Release files / toilmore_sdk-0.2.7-py3-none-any.whl
| Download URL | toilmore_sdk-0.2.7-py3-none-any.whl |
|---|---|
| Size | 26.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4734913dfaa6f3a54eeb9ec2870a7a2bafc16fb0cedda361b3ff48bf66a88a9
|
|
BLAKE2b-256 checksum How to use checksums |
d9d050136fee3b9d1ff95359fb52943bb03bce3f65e8e2a9c39288b38a2bd051
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.26.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5
|
Security for toilmore-sdk 0.2.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.