Skip to main content

Base64 image encoding/decoding with LLM API support

Project description

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

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

b64image-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

b64image-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file b64image-0.1.0.tar.gz.

File metadata

  • Download URL: b64image-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for b64image-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7ad911f0bac50903380dbfe1beba4305487581ef6a48b03ee741f29161777cf
MD5 3367f82f1924b96028430659490c2349
BLAKE2b-256 4e6f5b88f0c28432e46f3f39a55d0e8eef6b7a50f21584a953b1feec8eae6830

See more details on using hashes here.

File details

Details for the file b64image-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: b64image-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for b64image-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56fa6044022af9c7490b6143763d74a48580f2a5ac1762f7f27ae03b7c1ca5b0
MD5 418fad0af6e6ab549c88761830d8e5ba
BLAKE2b-256 aeba7862dfa7d69f9fe643489bd07ebcd9320cadf33b1118f74a3acec6add594

See more details on using hashes here.

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