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")
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)
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" |
"rgba" |
Color channels |
bg_color |
str |
None |
Background color (when channels="rgb") |
size |
"full" | "preview" | "small" | "medium" | "large" |
"full" |
Output size |
crop |
bool |
False |
Crop to subject bounds |
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
poofbg-0.1.0.tar.gz
(7.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file poofbg-0.1.0.tar.gz.
File metadata
- Download URL: poofbg-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b597f4b623c89d4dceb3f4b06a8785063229d5e576cc8b3ccbd0b95443636b6
|
|
| MD5 |
1a3b3e9170eab53778a94baace341f8e
|
|
| BLAKE2b-256 |
f01b281a6956b30f969d669c944aef42254110de7b455ce51326cedb99482616
|
File details
Details for the file poofbg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: poofbg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75abc14c186806f26c08bfb23c7f7dabfb1728522fc2877d8264684a3ddb5f1
|
|
| MD5 |
0b144cd85b4b1a8458093c749ca9308a
|
|
| BLAKE2b-256 |
75bb7ea7c803f2e718b667df4cf25e0db976167ea2e0c6f1f9b542046a5f0981
|