Skip to main content

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.

Install pixlub, write a script, run a real request and get the cut-out

Install

pip install pixlub

Quick start

  1. Create an API key in your Pixlub dashboard. API keys need a paid plan.

  2. Put it in an environment variable, never in your source code:

    export PIXLUB_API_KEY="pix.xxxxxxxx.xxxxxxxx..."
    
  3. 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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pixlub 0.3.2
File Size Uploaded Provenance Actions
pixlub-0.3.2.tar.gz 51.7 kB With provenance Details for pixlub-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pixlub 0.3.2
File Interpreter ABI Platform Actions
pixlub-0.3.2-py3-none-any.whl Python 3 none any Details for pixlub-0.3.2-py3-none-any.whl

Total release size: 85.3 kB

Release files / pixlub-0.3.2.tar.gz

Download URL pixlub-0.3.2.tar.gz
Size 51.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8da90529efb09764e85f132d11ec0a5a588ba007b92037537c27e54969b2c6b3
BLAKE2b-256 checksum
How to use checksums
2cd074ba562b1d38fbeef5d5c6af41f8102103baf2411b9a3579f6aefda12483
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 log

Release files / pixlub-0.3.2-py3-none-any.whl

Download URL pixlub-0.3.2-py3-none-any.whl
Size 33.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d323003fc49092e009b5ac5241108745402af85df525afe0ef87743a36d9f9b8
BLAKE2b-256 checksum
How to use checksums
9a703a97c4becab4d1ac1cf0d62d82380f1cf8635c797143f55b3fdc79d450f4
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 log

Security for pixlub 0.3.2

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.

Select from 2 files

Attestation for pixlub-0.3.2.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 log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page