AI-powered background removal with local and cloud options
Project description
withoutbg - Python SDK
AI-powered background removal with local and cloud options.
📚 View Complete Documentation →
Installation
# Using uv (recommended)
uv add withoutbg
# Or with pip
pip install withoutbg
Don't have
uvyet? Download it at astral.sh/uv - it's a fast, modern Python package installer.
Quick Start
Choose Your Model:
from withoutbg import WithoutBG
# Local processing with Open Source model
model = WithoutBG.opensource()
result = model.remove_background("input.jpg")
result.save("output.png")
# withoutBG Pro for best quality
model = WithoutBG.api(api_key="sk_your_key")
result = model.remove_background("input.jpg")
result.save("output.png")
API Usage
Single Image Processing
from withoutbg import WithoutBG
# Initialize model once
model = WithoutBG.opensource()
# Process image
result = model.remove_background("photo.jpg")
result.save("photo-withoutbg.png")
# Process with progress callback
def progress(value):
print(f"Progress: {value * 100:.1f}%")
result = model.remove_background("photo.jpg", progress_callback=progress)
Batch Processing
from withoutbg import WithoutBG
# Initialize model once (efficient!)
model = WithoutBG.opensource()
# Process multiple images - model is reused for all images
images = ["photo1.jpg", "photo2.jpg", "photo3.jpg"]
results = model.remove_background_batch(images, output_dir="results/")
# Or process without saving
results = model.remove_background_batch(images)
for i, result in enumerate(results):
result.save(f"output_{i}.png")
Using withoutBG Pro
from withoutbg import WithoutBG
# Initialize API client
model = WithoutBG.api(api_key="sk_your_key")
# Process images
result = model.remove_background("input.jpg")
# Batch processing with withoutBG Pro
results = model.remove_background_batch(
["img1.jpg", "img2.jpg", "img3.jpg"],
output_dir="api_results/"
)
Advanced: Direct Model Access
from withoutbg import OpenSourceModel, ProAPI
# For advanced users who need direct control
opensource_model = OpenSourceModel()
result = opensource_model.remove_background("input.jpg")
# Or with custom model paths
# Models can be downloaded from: https://huggingface.co/withoutbg/focus
model = OpenSourceModel(
depth_model_path="/path/to/depth.onnx",
isnet_model_path="/path/to/isnet.onnx",
matting_model_path="/path/to/matting.onnx",
refiner_model_path="/path/to/refiner.onnx"
)
# Direct withoutBG Pro API access
api = ProAPI(api_key="sk_your_key")
result = api.remove_background("input.jpg")
usage = api.get_usage()
CLI Usage
# Process single image
withoutbg photo.jpg
# Batch processing
withoutbg photos/ --batch --output-dir results/
# Use withoutBG Pro
withoutbg photo.jpg --api-key sk_your_key
# Specify output format
withoutbg photo.jpg --format jpg --quality 90
Features
- ✨ Local processing with Focus v1.0.0 model (free, ~320MB download)
- 🚀 withoutBG Pro for best quality results
- 📦 Batch processing support
- 🎯 Python API and CLI
- 🔧 Flexible output formats (PNG, JPEG, WebP)
- ⚡ Efficient model loading - load once, process many images
Performance
Local Model:
- First run: ~5-10 seconds (~320MB download from HuggingFace)
- CPU: ~2-5 seconds per image
- Memory: ~2GB RAM
withoutBG Pro:
- ~1-3 seconds per image (network dependent)
- No local resources needed
Configuration
Model Path Environment Variables
By default, models are downloaded from HuggingFace Hub. You can override this by setting environment variables to use local model files:
export WITHOUTBG_DEPTH_MODEL_PATH=/path/to/depth_anything_v2_vits_slim.onnx
export WITHOUTBG_ISNET_MODEL_PATH=/path/to/isnet.onnx
export WITHOUTBG_MATTING_MODEL_PATH=/path/to/focus_matting_1.0.0.onnx
export WITHOUTBG_REFINER_MODEL_PATH=/path/to/focus_refiner_1.0.0.onnx
Model Files (total ~320MB):
- ISNet segmentation: 177 MB
- Depth Anything V2: 99 MB
- Focus Matting: 27 MB
- Focus Refiner: 15 MB
This is useful for:
- Offline environments
- CI/CD pipelines
- Custom model versions
- Faster startup times (no download needed)
Documentation
- Python SDK Documentation - Complete online documentation
- Focus Model Results - See example outputs
- Pro API Results - See example outputs
- Compare Models - Focus vs Pro comparison
- Main Project README - Local documentation
Development
# Install in development mode (using uv - recommended)
uv sync --extra dev
# Or with pip
pip install -e ".[dev]"
# Run tests
pytest
# Type checking
mypy src/
# Format code
black src/ tests/
ruff check src/ tests/
License
Apache License 2.0 - see LICENSE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 withoutbg-1.0.2.tar.gz.
File metadata
- Download URL: withoutbg-1.0.2.tar.gz
- Upload date:
- Size: 283.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a035fc2026e75c6b9ca9b4cf630ad0e52207df69b4a5d1d1f4d6b81c92b2ea6a
|
|
| MD5 |
41a05f220ce66bb9149561958d5d91cc
|
|
| BLAKE2b-256 |
ebf8d4778073bc9748d60c3fdfee2847fa4c1f0b071d99f50ce667a1be6be48a
|
File details
Details for the file withoutbg-1.0.2-py3-none-any.whl.
File metadata
- Download URL: withoutbg-1.0.2-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7e49996533f8976d5a316066b7622b66d87e47e79e1e3f5cd1747c987353033
|
|
| MD5 |
f2583c602139417f07dd24c4460886b1
|
|
| BLAKE2b-256 |
cf7931a4c4feb24594f66c032b35174c2365985fe00e2e213dc2a3dc4e7dffe4
|