---
title: Python Bindings
description: Use VisionSqueezer from Python via native pyo3 wheels.
navigation:
icon: i-lucide-file-code
---
`pip install vision-squeezer` ships native wheels (pyo3 + maturin) for Linux, macOS, and Windows. No Rust toolchain required.
```bash [Terminal]
pip install vision-squeezer
```
## API
### `optimize_image`
```python
import vision_squeezer as vs
report = vs.optimize_image(
"screenshot.png", # str path or bytes
model="gpt6", # gpt6 | claude | gemini | legacy/open-weight aliases
quality=75,
format="jpeg", # jpeg | webp | avif
smart_crop=False,
auto_quality=None, # e.g. 0.95 to target SSIM
output_path=None, # write to disk if set
)
print(report["tokens_saved"], report["size_reduction_pct"])
```
Inputs accept both `str` (file paths) and `bytes` (raw image data). The returned `dict` contains `bytes`, `base64`, dimensions, byte counts, token counts, and the chosen quality.
### `estimate_tokens`
```python
vs.estimate_tokens(width=2400, height=1670, model="claude")
# -> { "tokens": ... }
```
### `optimal_dimensions`
```python
vs.optimal_dimensions(width=4096, height=3072, model="gpt6")
# -> { "width": ..., "height": ... }
```
## Pipeline example
```python
import vision_squeezer as vs
# Estimate before committing
est = vs.estimate_tokens(4096, 3072, model="gpt6")
if est["tokens"] > 1000:
vs.optimize_image(
"large.png",
model="gpt6",
auto_quality=0.95,
format="avif",
output_path="large.optimized.avif",
)
```