Skip to main content

b64image

Base64 image encoding/decoding with LLM API support.

Installation

uv add b64image

Usage

Python API

from b64image import Base64Image, to_openai, to_anthropic, create_vision_message

# Load from various sources
img = Base64Image.from_path("photo.png")
img = Base64Image.from_url("https://example.com/image.jpg")
img = Base64Image.from_bytes(raw_bytes)
img = Base64Image.from_base64("iVBORw0KGgo...")
img = Base64Image.from_auto("photo.png")  # auto-detect source type

# Convert to outputs
img.to_bytes()        # raw bytes
img.save("output.png") # save to file
img.data_uri          # data:image/png;base64,...

# LLM API formats
to_openai(img)     # OpenAI vision format
to_anthropic(img)  # Anthropic Claude format
to_google(img)     # Google Gemini format

# Create complete vision message
msg = create_vision_message(
    "What's in this image?",
    [img],
    provider="openai"  # or "anthropic", "google"
)

Batch Processing

from b64image import load_images, load_images_from_directory

# Load multiple images
for img in load_images(["a.png", "b.jpg", "https://example.com/c.webp"]):
    print(img.ext, img.size_bytes)

# Load from directory
for img in load_images_from_directory("./images", recursive=True):
    print(img.data_uri)

CLI

# Encode image to base64
b64image encode photo.png
b64image encode photo.png --format raw
b64image encode photo.png --llm openai

# Encode directory
b64image encode ./images/ -r

# Decode base64 to file
b64image decode "data:image/png;base64,..." -o output.png

# Show image info
b64image info photo.png

Supported Formats

JPEG, PNG, GIF, WebP, BMP

Metadata

Release files for b64image 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for b64image 0.1.2
File Size Uploaded
b64image-0.1.2.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for b64image 0.1.2
File Interpreter ABI Platform
b64image-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / b64image-0.1.2.tar.gz

Download URL b64image-0.1.2.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b02bb563458cd862a955809e1f18bf959cc51d3446fc0bae87a5e9382a3bb248
BLAKE2b-256 checksum
How to use checksums
d56218d38e3008d7c5b42780f33ade75476a08cfdcefbefde8e5fb3abe88de87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / b64image-0.1.2-py3-none-any.whl

Download URL b64image-0.1.2-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59dbb6274ed8b2308b8f120473710bfd64a65c5755d7f10d067f2e531ddc655e
BLAKE2b-256 checksum
How to use checksums
87fe91b84e45cb321bc61685c6eb81c5127408bf7ffa1691f751f6beede03cd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page