poofbg
The official Python SDK for the Poof background removal API.
Installation
pip install poofbg
Quick Start
from poof import Poof
# Initialize the client
client = Poof(api_key="your-api-key")
# Remove background from an image
result = client.remove_background("photo.jpg")
# Save the result
result.save("output.png")
Usage
Remove Background
from poof import Poof
client = Poof(api_key="your-api-key")
# From a file path
result = client.remove_background("image.jpg")
# From bytes
with open("image.jpg", "rb") as f:
image_bytes = f.read()
result = client.remove_background(image_bytes)
# From a file object
with open("image.jpg", "rb") as f:
result = client.remove_background(f)
# Save the result
result.save("output.png")
# Or get the bytes directly
image_data = result.data
# or: image_data = bytes(result)
Options
# Different output format
result = client.remove_background("photo.jpg", format="webp")
# Crop to subject bounds
result = client.remove_background("photo.jpg", crop=True)
# RGB output with background color (no transparency)
result = client.remove_background(
"photo.jpg",
channels="rgb",
bg_color="#ffffff"
)
# Different size presets
result = client.remove_background("photo.jpg", size="preview")
# Exact output size, never stretched: subject cropped, then fitted into 500x500
result = client.remove_background("photo.jpg", crop=True, width=500, height=500)
# Fill the canvas instead (overflow cropped around the subject), on white
result = client.remove_background(
"photo.jpg", width=1080, height=1080, fit="cover", format="jpg", bg_color="#ffffff"
)
# Cap the width and keep the aspect ratio; small images are left as they are
result = client.remove_background("photo.jpg", width=1000, fit="scale-down")
Result Metadata
result = client.remove_background("photo.jpg")
print(f"Image size: {result.width}x{result.height}")
print(f"Processing time: {result.processing_time_ms}ms")
print(f"Content type: {result.content_type}")
print(f"Request ID: {result.request_id}")
Account Info
info = client.me()
print(f"Plan: {info['plan']}")
print(f"Credits used: {info['usedCredits']} / {info['maxCredits']}")
Context Manager
with Poof(api_key="your-api-key") as client:
result = client.remove_background("photo.jpg")
result.save("output.png")
# Client is automatically closed
Error Handling
from poof import (
Poof,
PoofError,
AuthError,
RateLimitError,
PaymentRequiredError,
ValidationError,
)
client = Poof(api_key="your-api-key")
try:
result = client.remove_background("photo.jpg")
except AuthError as e:
print(f"Authentication failed: {e.message}")
except PaymentRequiredError as e:
print(f"Insufficient credits: {e.message}")
except RateLimitError as e:
print(f"Rate limited: {e.message}")
except ValidationError as e:
print(f"Invalid request: {e.message}")
except PoofError as e:
print(f"API error: {e.message} (code: {e.code})")
All exceptions include:
message: Human-readable error descriptioncode: Machine-readable error codedetails: Additional troubleshooting inforequest_id: Unique ID for supportstatus_code: HTTP status code
Configuration
# Custom timeout (default: 60 seconds)
client = Poof(api_key="...", timeout=120)
# Custom base URL
client = Poof(api_key="...", base_url="https://api.example.com/v1")
# Bring your own httpx client
import httpx
with httpx.Client(timeout=30, http2=True) as http_client:
client = Poof(api_key="...", httpx_client=http_client)
result = client.remove_background("photo.jpg")
API Reference
Poof(api_key, *, base_url, timeout, httpx_client)
Create a new Poof client.
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
required | Your Poof API key |
base_url |
str |
https://api.poof.bg/v1 |
API base URL |
timeout |
float |
60.0 |
Request timeout in seconds |
httpx_client |
httpx.Client |
None |
Custom HTTP client |
client.remove_background(image, *, format, channels, bg_color, size, crop, padding, width, height, fit)
Remove background from an image.
| Parameter | Type | Default | Description |
|---|---|---|---|
image |
str | Path | bytes | BinaryIO |
required | Image to process |
format |
"png" | "jpg" | "webp" |
"png" |
Output format |
channels |
"rgba" | "rgb" | "alpha" |
"rgba" |
Color channels (alpha = grayscale mask only) |
bg_color |
str |
None |
Background color (when channels is "rgb" or "rgba") |
size |
"full" | "preview" | "medium" | "hd" |
"full" |
Output size preset (megapixel cap); ignored when width/height is set |
crop |
bool | str |
False |
Crop to subject bounds, or an aspect ratio like "1:1" |
padding |
str |
"10%" |
Padding around the subject when cropping ("10%", "0.1", or "10%,7.5%") |
width |
int |
None |
Output width in pixels (1-6000); alone, height follows the aspect ratio |
height |
int |
None |
Output height in pixels (1-6000); alone, width follows the aspect ratio |
fit |
"contain" | "cover" | "scale-down" |
"contain" |
How to fit into width x height without stretching: pad, crop the overflow, or pad without enlarging |
Returns a RemoveBackgroundResult with:
data: Image bytescontent_type: MIME typewidth,height: Image dimensionsprocessing_time_ms: Processing timerequest_id: Request ID for supportsave(path): Save to file
client.me()
Get account information.
Returns an AccountInfo dict:
organizationId: Organization IDplan: Plan namemaxCredits: Total creditsusedCredits: Used creditsautoRechargeThreshold: Auto-recharge threshold (if enabled)
License
MIT
Metadata
Release files for poofbg 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| poofbg-0.2.0.tar.gz | 8.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| poofbg-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.9 kB
Release files / poofbg-0.2.0.tar.gz
| Download URL | poofbg-0.2.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
366e4b86140f1f0d99189c031a912b6ea0a16a2af5198ef7ed19140be9094e3e
|
|
BLAKE2b-256 checksum How to use checksums |
5773290c5839d7dd30da7c7834302430ea775f8940b35c867af0780d9480a28e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency logRelease files / poofbg-0.2.0-py3-none-any.whl
| Download URL | poofbg-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
680c73cb665a3f5c3e954dae371fac74d2e8b6c525c0f30281ad17a4a9ddf973
|
|
BLAKE2b-256 checksum How to use checksums |
98fdc8b950036a6177ebbb7743748f09b1f6c496ab4e57c5d8588c2470b88c4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 7, 2026.
Transparency log