Skip to main content

Abraia Python SDK

Project description

PyPI Build Status Coverage Status Analytics

Abraia API client for Python

Python client for the Abraia API. Batch optimize images for web with no quality damage based on perception-driven technology.

  • Optimal image compression with our perceptual adjustment to preserve the quality and maximize the compression.
  • Smart crop and resize images with our saliency and aesthetic based model which balances between content and aesthetics.

Automatically crop, resize, and compress images for web.

Installation

The Abraia python client and CLI works in Windows, Mac, and Linux with Python 2 and 3 (python>=2.6.5), and can be installed and upgraded with a simple command:

python -m pip install -U abraia

Moreover, you have to configure your ABRAIA_KEY as an environment variable:

export ABRAIA_KEY=api_key

On Windows you need to use set instead of export:

set ABRAIA_KEY=api_key

NOTE: To persist the configuration use your system options to set your ABRAIA_KEY environment variable and avoid to run the previous command every time you start a terminal/console session.

Fluent API

The Abraia fluent API is the easiest way to resize and compress images with Python. You just need to define the source of the image, the transformation operation, and the sink for the resultant image.

For instance, to optimize a batch of JPEG images limiting the maximum size to 2000 pixels width:

from glob import glob
from abraia import Abraia

abraia = Abraia()

paths = glob('images/*.jpg')
for path in paths:
    abraia.from_file(path).resize(width=2000).to_file(path+'o')

Compress images

To compress an image you just need to specify the input and output paths for the image:

abraia.from_file('images/lion.jpg').to_file('images/lion_o.jpg')
abraia.from_file('images/jaguar.png').to_file('images/jaguar_o.png')

You can also compress and image directly from an url:

abraia.from_url('https://api.abraia.me/files/demo/birds.jpg').to_file('images/birds_o.jpg')

Image compressed from url

Resize images

To resize an image you just need to specify the width or the height of the image:

abraia.from_file('images/lion.jpg').resize(width=500).to_file('images/lion_500.jpg')

Image lion resized

You can also automatically crop and resize and image to change the aspect ratio specifying both width and height size parameters:

abraia.from_file('images/lion.jpg').resize(width=333, height=333).to_file('images/lion_333x333.jpg')

Image lion smart cropped

Convert images

To convert images to a web format (JPEG, PNG, WebP, GIF) or between these formats you just need to change the filename extension for the destination file:

abraia.from_file('images/jaguar.png').to_file('jaguar.webp')
abraia.from_file('images/jaguar.png').to_file('jaguar.jpg')

PNG Jaguar optimized WEBP Jaguar optimized JPEG Jaguar optimized

Optimized PNG (16.1KB) vs optimized WebP (6.5KB) vs optimized JPEG (14.4KB)

Watermark images

Using templates images can be easily edited and consistently branded. You just need to create a template in the web editor to watermark your images.

abraia.from_file('images/lion.jpg').process({'action': 'test.atn'}).resize(width=333).to_file('images/lion_brand.jpg')

Branded lion

As a result you get a perfectly branded and optimized image ready to be used on your website, ecommerce, marketplace, or social media.

License

This software is licensed under the MIT License. View the license.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abraia-0.6.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

abraia-0.6.3-py2.py3-none-any.whl (9.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file abraia-0.6.3.tar.gz.

File metadata

  • Download URL: abraia-0.6.3.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.6.7

File hashes

Hashes for abraia-0.6.3.tar.gz
Algorithm Hash digest
SHA256 8502f14118953f68dc945dfa0355b3fdd82cbaeb7f4023b294f5859becc7a322
MD5 c35e484aa1e71406ff1167aabdd983b6
BLAKE2b-256 ce82cb5e2532b8b1bdc3ca0ff0c7902b7eb7d4674accf72b045f8173edebe606

See more details on using hashes here.

File details

Details for the file abraia-0.6.3-py2.py3-none-any.whl.

File metadata

  • Download URL: abraia-0.6.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.6.7

File hashes

Hashes for abraia-0.6.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9549c832bc2d32ee25223b5ffeef821930d5df8c6f6bc3c2d5ff7e7db050962d
MD5 c2161003b76bf6c7f842038129fd901d
BLAKE2b-256 fa6fa42eec199107372baa64bb42ff5936c8c90a9a91271b1ce31d07054a40fd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page