Skip to main content

AI-powered background removal with local and cloud options

Project description

withoutbg - Python SDK

AI-powered background removal with local and cloud options.

PyPI License

📚 View Complete Documentation →

Installation

# Using uv (recommended)
uv add withoutbg

# Or with pip
pip install withoutbg

Don't have uv yet? 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

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

withoutbg-1.0.3.tar.gz (283.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

withoutbg-1.0.3-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file withoutbg-1.0.3.tar.gz.

File metadata

  • Download URL: withoutbg-1.0.3.tar.gz
  • Upload date:
  • Size: 283.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for withoutbg-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4f3197ea8c62bdf146f1146ad5941532f70b4d74f3d02d82cc5b51797642001b
MD5 e65c139d2df829148ef47122a4d6bfef
BLAKE2b-256 ed32cbe0c67751e014f97ad2ad522e4a263f09bb4d183c80fa81c0cfac9056fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for withoutbg-1.0.3.tar.gz:

Publisher: release.yml on withoutbg/withoutbg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file withoutbg-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: withoutbg-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for withoutbg-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0532b27c40d90a379306416f8adba686b872d870a118b1a385e65c29d98496c9
MD5 230fc8003d5e18ebb877a02842764751
BLAKE2b-256 413042c09e9e61874f7d9e0c37af5a84bcd6839a7c4bfe0fa39b3ae62f91c04e

See more details on using hashes here.

Provenance

The following attestation bundles were made for withoutbg-1.0.3-py3-none-any.whl:

Publisher: release.yml on withoutbg/withoutbg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page