Pixelbin SDK for Python
Project description
Pixelbin Backend SDK for Python
Pixelbin Backend SDK for python helps you integrate the core Pixelbin features with your application.
Getting Started
Getting started with Pixelbin Backend SDK for Python
Installation
pip install pixelbin
Usage
Quick Example
import asyncio
from pixelbin import PixelbinClient, PixelbinConfig
# create client with your API_TOKEN
config = PixelbinConfig({
"domain": "https://api.pixelbin.io",
"apiSecret": "API_TOKEN",
})
# Create a pixelbin instance
pixelbin:PixelbinClient = PixelbinClient(config=config)
# Sync method call
try:
result = pixelbin.assets.listFiles()
print(result)
except Exception as e:
print(e)
# Async method call
try:
result = asyncio.get_event_loop().run_until_complete(pixelbin.assets.listFilesAsync())
print(result)
except Exception as e:
print(e)
Utilities
Pixelbin provides url utilities to construct and deconstruct Pixelbin urls.
url_to_obj
Deconstruct a pixelbin url
| parameter | description | example |
|---|---|---|
| pixelbinUrl (string) | A valid pixelbin url | https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg |
Returns:
| property | description | example |
|---|---|---|
| cloudName (string) | The cloudname extracted from the url | your-cloud-name |
| zone (string) | 6 character zone slug | z-slug |
| version (string) | cdn api version | v2 |
| options (object) | optional query parameters | |
| transformations (array) | Extracted transformations from the url | |
| filePath | Path to the file on Pixelbin storage | /path/to/image.jpeg |
| baseUrl (string) | Base url | https://cdn.pixelbin.io/ |
Example:
from pixelbin.utils.url import url_to_obj
pixelbinUrl = "https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg?dpr=2.0&f_auto=True"
obj = url_to_obj(pixelbinUrl)
# obj
# {
# "cloudName": "your-cloud-name",
# "zone": "z-slug",
# "version": "v2",
# "options": {
# "dpr": 2.0,
# "f_auto": True,
# },
# "transformations": [
# {
# "plugin": "t",
# "name": "resize",
# "values": [
# {
# "key": "h",
# "value": "100"
# },
# {
# "key": "w",
# "value": "200"
# }
# ]
# },
# {
# "plugin": "t",
# "name": "flip",
# }
# ],
# "filePath": "path/to/image.jpeg",
# "baseUrl": "https://cdn.pixelbin.io"
# }
obj_to_url
Converts the extracted url obj to a Pixelbin url.
| property | description | example |
|---|---|---|
| cloudName (string) | The cloudname extracted from the url | your-cloud-name |
| zone (string) | 6 character zone slug | z-slug |
| version (string) | cdn api version | v2 |
| options (object) | optional query parameters | |
| transformations (array) | Extracted transformations from the url | |
| filePath | Path to the file on Pixelbin storage | /path/to/image.jpeg |
| baseUrl (string) | Base url | https://cdn.pixelbin.io/ |
from pixelbin.utils.url import obj_to_url
obj = {
cloudName: "your-cloud-name",
zone: "z-slug",
version: "v2",
options: {
dpr: 2.0,
f_auto: True,
},
transformations: [
{
plugin: "t",
name: "resize",
values: [
{
key: "h",
value: "100",
},
{
key: "w",
value: "200",
},
],
},
{
plugin: "t",
name: "flip",
},
],
filePath: "path/to/image.jpeg",
baseUrl: "https://cdn.pixelbin.io",
}
url = obj_to_url(obj) # obj is as shown above
# url
# https://cdn.pixelbin.io/v2/your-cloud-name/z-slug/t.resize(h:100,w:200)~t.flip()/path/to/image.jpeg?dpr=2.0&f_auto=True
Documentation
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
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 pixelbin-2.2.0.tar.gz.
File metadata
- Download URL: pixelbin-2.2.0.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.16 Darwin/21.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44fd1cb06e207ec9260249ecc4d6acbe404f864b21b15800cdfc9ab463094db2
|
|
| MD5 |
bd8b72733ceda51aaa34850220b66d6c
|
|
| BLAKE2b-256 |
2c2a7c911d61ec77686bb1fb511b8097b1922f01db445cc46ee495563361e344
|
File details
Details for the file pixelbin-2.2.0-py3-none-any.whl.
File metadata
- Download URL: pixelbin-2.2.0-py3-none-any.whl
- Upload date:
- Size: 48.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.8.16 Darwin/21.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c961a2f536fbb826710cd90b462e4f6545d4fb50c59097349d7499c5c0271aa
|
|
| MD5 |
662510357f613df8a42e075b0f4316d7
|
|
| BLAKE2b-256 |
f6c1adfea1bb572422a8501d34a09f96843745fb8e5bbf4751f7e17855ab256d
|