withoutbg/withoutbg-python

Python SDK for local and cloud background removal (pip install withoutbg)

What it solves

It provides a simple way to remove backgrounds from images using Python, offering a choice between a free, private local model or a high-quality cloud-based API.

How it works

The library uses a unified ONNX graph (WBGNet) that combines depth estimation, segmentation, matting, and refinement into a single inference pass. Users can choose between two modes via a single API: open_weights() for local execution (downloading a ~495MB model from Hugging Face) or api() for cloud-based processing via an API key.

Who it’s for

  • Developers needing offline or private image processing.
  • Users processing large batches of images who want to avoid per-image costs.
  • Product developers who prefer a managed cloud service with higher quality (especially for hair and fur) and zero infrastructure overhead.

Highlights

  • Dual-mode API: Switch between local and cloud processing with one line of code.
  • Local Execution: Runs on CPU via ONNX, requiring no GPU.
  • Batch Processing: Supports processing multiple images efficiently with a single model load.
  • CLI Tool: Includes a command-line interface for quick background removal and batch jobs.
  • Flexible Output: Returns PIL Images in RGBA mode, supporting PNG and WebP for transparency.