httpx.
Installation
The package on PyPI is
poofbg, but the import name is poof.Quick Start
Authentication
api_key is required. The SDK does not read an environment variable for you, so load it yourself:
client.close() when you are done:
Usage Examples
From File Path
pathlib.Path objects work too.
From Bytes
From a File-like Object
From URL
Download the image first, then pass the bytes:With Options
channels="alpha", padding, aspect-ratio crop, the matte metadata fields and the width / height / fit output-size options need poofbg 0.2.0 or later; video needs 0.3.0 or later.Result Object
remove_background() returns a RemoveBackgroundResult:
Flagging Results for Review
matte_confidence (0–1) is how decisive the alpha mask is; matte_ambiguous_ratio (0–1) is the fraction of pixels with alpha between 0.1 and 0.9. Both are heuristics, not calibrated probabilities. The dashboard playground flags a result for review when the ambiguous ratio is above 0.15:
Account Info
client.me() returns the /me response as a plain dict. It is free and not rate limited.
Parallel Processing
The client is synchronous. To process several images at once, use a thread pool:Error Handling
All exceptions inherit fromPoofError and are chosen by HTTP status:
Every exception exposes
.message, .code, .details, .request_id and .status_code.
Retry with Backoff
Configuration
Type Hints
The SDK ships type hints and apy.typed marker, so mypy and IDEs understand Poof, RemoveBackgroundResult and the exception classes:
Video
remove_background() accepts video too (poofbg 0.3.0 or later). Poof detects the media type from the bytes: an image returns a RemoveBackgroundResult as above, a video is accepted as an asynchronous job and the call returns a Job instead. Wait for the job, then download its result_url.
format="gif" returns a looping transparent GIF (1-bit transparency, no audio, capped at 1280 px on the longest side, 720p for widescreen, and 50 fps) for stickers and chat.
Pass wait=True to block inside the call instead:
https URL instead of uploading them:
Video options
crop, padding, width, height and fit are image-only; sending one with a video raises ValidationError.
Job fields
wait_for_job(job, *, poll_interval=3.0, timeout=600.0, on_progress=None) polls GET /jobs/{id} (free, not rate limited) and raises PoofError with code="job_failed" if the job fails, or code="timeout" after timeout seconds. The full job lifecycle is described in the Jobs reference.