pixlub
Official Python SDK for the Pixlub API. Python 3.9+, one dependency: httpx.
Documentation: getting started with the API and every module, its inputs and settings.
https://github.com/user-attachments/assets/b8ecd6c0-b65e-4c05-ae60-68e3d71c888a
Install
pip install pixlub
Quick start
-
Create an API key in your Pixlub dashboard. API keys need a paid plan.
-
Put it in an environment variable, never in your source code:
export PIXLUB_API_KEY="pix.xxxxxxxx.xxxxxxxx..."
-
Run a tool:
import pixlub client = pixlub.Client() result = client.tools.run("removeBgApi", image="photo.jpg") result.save(f"photo-nobg{result.extension}")
result.extension matches the produced file: .webp for removeBgApi, .png
for most tools. save() refuses to replace an existing file unless
overwrite=True.
Results
result = client.tools.run("faceBlurApi", image="photo.jpg", params={"mode": "auto"})
result.image # bytes of the produced file (None if the tool only returns data)
result.data # the data output, parsed JSON
result.cost # credits charged
result.credits_balance # credits left
result.output("out") # an output by key, or by name ("image", "data", "file")
for output in result.outputs:
print(output.key, output.name, output.content_type, len(output.content))
In a batch, output keys get the rank of the file: out#0, out#1… Each
output.url is a download link valid for one hour.
Tools and settings
for tool in client.tools.list(executable_only=True):
print(tool.id, [i.id for i in tool.inputs], [o.key for o in tool.outputs])
schema = client.tools.schema("flip") # JSON Schema of the settings
client.tools.run("flip", image="photo.jpg", params={"axis": "v"})
Invalid settings raise InvalidRequestError, with the reasons in details.
Several files
A tool with several inputs takes inputs=, keyed by input id. An input that
takes several files takes a list:
client.tools.run("mask", inputs={"image": "photo.png", "mask": "mask.png"})
client.tools.run("merge", inputs={"base": "bg.png", "overlay": ["1.png", "2.png"]})
client.tools.run("flip", image=["a.png", "b.png", "c.png"], params={"axis": "h"}) # 3 runs
When tool.inputs[i].per_file is true, each file is a separate run, charged
separately. A palette is passed in params, as a list of colors.
A file is a path, bytes, or a binary file object. To use a file from the web,
pass a pixlub.SourceURL; a plain string is always a local path.
client.tools.run("removeBgApi", image=pixlub.SourceURL("https://example.com/photo.jpg"))
Large files are handled automatically: call run() the same way.
Limits
| Limit | Value |
|---|---|
| File size, by plan | Free 10 MiB, Basic 50 MiB, Pro 3 GiB |
| File size, by tool | images 100 MiB, video and audio 3 GiB, Office 250 MiB |
| Image size | 40 megapixels |
| Files per run | 64 |
| Runs | 30 a minute per account, bursts of 10 |
| Download links | 1 hour |
Async
AsyncClient has the same methods:
import asyncio
import pixlub
async def main() -> None:
async with pixlub.AsyncClient() as client:
result = await client.tools.run("removeBgApi", image="photo.jpg")
result.save(f"photo-nobg{result.extension}")
asyncio.run(main())
Timeouts
run() waits for long runs until they finish, up to job_timeout (30 minutes
by default). After that, JobTimeoutError gives the job_id: the run may
still finish and may have been charged, so check it with GET /v1/jobs/{job_id}
rather than running the tool again.
client = pixlub.Client(timeout=30, job_timeout=600)
result = client.tools.run("removeBgApi", image="photo.jpg", job_timeout=3600)
Errors
API errors and refused arguments raise a pixlub.PixlubError. A wrong argument
type raises TypeError; a file that save() cannot write raises OSError.
| Exception | When |
|---|---|
ConfigurationError |
Missing or malformed key or base URL. |
InvalidInputError |
An argument was refused before anything was sent. |
UnknownToolError |
Unknown tool id. |
InvalidRequestError |
HTTP 400 or 422: invalid settings (details), image_too_large (max_pixels)… |
FileTooLargeError |
HTTP 413: file too large for the tool or your plan (max_bytes). |
AuthenticationError |
HTTP 401: unknown or revoked key. |
InsufficientCreditsError |
HTTP 402: not enough credits (required_credits). |
PermissionDeniedError |
HTTP 403: not included in your plan (code, limit). |
NotFoundError |
HTTP 404. |
RateLimitError |
HTTP 429: too many requests (retry_after). Never charged. |
ServerError, ServiceUnavailableError |
HTTP 5xx (retry_after). |
APIConnectionError, APITimeoutError |
No answer (request_sent). |
JobTimeoutError |
A run outlived job_timeout (job_id). |
UnexpectedResponseError |
The answer could not be read. |
Every APIError has http_status, code and message.
try:
result = client.tools.run("removeBgApi", image="photo.jpg")
except pixlub.InsufficientCreditsError as error:
print("Top up your credits:", error.required_credits)
except pixlub.APIError as error:
print(f"Refused ({error.http_status}): {error.message}")
Retries and credits
The SDK retries a request only when it cannot cause a second charge, up to
max_retries times (2 by default, 0 to disable), and waits as long as the API
asks. Arguments are checked before anything is sent: a mistake costs nothing.
After a timeout or a server error on a run, check your balance before running
it again.
Configuration
| Argument | Environment variable | Default |
|---|---|---|
api_key |
PIXLUB_API_KEY |
required |
base_url |
PIXLUB_BASE_URL |
https://api.pixlub.com (http:// only for localhost) |
timeout |
10 s connect, 180 s read, 60 s write | |
job_timeout |
1800 s | |
max_retries |
2 (0 to 5) | |
max_input_bytes |
3 GiB | |
http_client |
a new httpx.Client (pass one for proxies or custom TLS) |
Examples
examples/:
quickstart.py for a first script, batch_async.py for many images at once.
Development
pip install -e ".[dev]"
pytest
ruff check .
mypy
Live tests run against a real API, and running a tool costs credits:
PIXLUB_BASE_URL=https://api.pixlub.com PIXLUB_API_KEY=... pytest tests/test_live.py
License
MIT: see LICENSE.
Metadata
Release files for pixlub 0.3.1
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 |
|---|---|---|---|---|
| pixlub-0.3.1.tar.gz | 51.3 kB | With provenance | Details for pixlub-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pixlub-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for pixlub-0.3.1-py3-none-any.whl |
Total release size: 84.7 kB
Release files / pixlub-0.3.1.tar.gz
| Download URL | pixlub-0.3.1.tar.gz |
|---|---|
| Size | 51.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f7522063c5367adeae7564777d8b1a4b426c0064df133f584cbef26947a9d21
|
|
BLAKE2b-256 checksum How to use checksums |
5817ebcae22225b6d8c1e0e6c62b162ecb112ff0772c29971751fa918c33a64d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / pixlub-0.3.1-py3-none-any.whl
| Download URL | pixlub-0.3.1-py3-none-any.whl |
|---|---|
| Size | 33.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd6f97060ef4725933da65d786c9d1eb352147ae8fbb81611189b31e21ecb2e4
|
|
BLAKE2b-256 checksum How to use checksums |
0098dbd147e7988de841aa625b0de16b51ba57a3f9ab532518f9b10fbe094603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for pixlub 0.3.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pixlub-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA 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.