Github:github.com/iyume/ilove…
基于 iLoveAPI (www.iloveapi.com/docs/api-re…) 封装的 iLoveIMG & iLovePDF 客户端 Python 实现。
之前经常用 iloveimg 的图像服务,压缩率非常高,速度也很快。今天做一些自动化时想要用它的 API,但是发现它没有 Python 的客户端实现,于是编写了一份。
没有体验过的可以先去官网体验一下:
iLoveIMG:www.iloveimg.com/
iLovePDF: www.ilovepdf.com/
注册账号即可得到 API Key。每月 2500 额度,可供 2500 次任务调用,非常良心。
特点
-
完整的类型提示
-
asyncio 异步支持
-
REST API 与 workflow API
示例
压缩图像:
from iloveapi import ILoveApi
client = ILoveApi(
public_key="<project_public_******>",
secret_key="<secret_key_******>",
)
task = client.create_task("compressimage")
task.process_files("p1.png")
task.download("output.png")
多张图像:
task = client.create_task("compressimage")
task.process_files(
"p1.png",
("custom_name.png", "p2.png"),
("custom_name.png", b"..PNG..."),
{
"file": b"..PNG...",
"filename": "custom_name.png",
"rotate": 2, # add image parameter
"password": "xxx", # for PDF
}
)
task.download("output.zip") # zip format
异步支持:
task = await client.create_task_async("compressimage")
await task.process_files_async("p1.png")
await task.download_async("output.png")
REST API:
response = client.rest.start("compressimage") # getting httpx response
response = await client.rest.start_async("compressimage") # async