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
Release history Release notifications | RSS feed
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.1.tar.gz
(8.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file b64image-0.1.1.tar.gz.
File metadata
- Download URL: b64image-0.1.1.tar.gz
- Upload date:
- Size: 8.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9dc5756a0b016f0f30171d1dd0fc85d5c70f8d132c7ebc8d8986edbc731a9ca
|
|
| MD5 |
4f175d218bfedb4f63dad75daa3a732e
|
|
| BLAKE2b-256 |
4c152f4de0a391136a62a131826d84f7dde37f88949ff5ae1d2998d1e302bdcd
|
File details
Details for the file b64image-0.1.1-py3-none-any.whl.
File metadata
- Download URL: b64image-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
684af8884a846588f53d2ee49275120a760b1fda79aa1f0e87ecc1f3200c3998
|
|
| MD5 |
4c7cdee2a2046c506d7012d1a7b3101d
|
|
| BLAKE2b-256 |
382a9d105240ae0e9976de8c998b0e3c1208351477a3f1502f5e232355baaf1f
|