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.2.tar.gz
(9.3 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
b64image-0.1.2-py3-none-any.whl
(10.5 kB
view details)
File details
Details for the file b64image-0.1.2.tar.gz.
File metadata
- Download URL: b64image-0.1.2.tar.gz
- Upload date:
- Size: 9.3 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 |
b02bb563458cd862a955809e1f18bf959cc51d3446fc0bae87a5e9382a3bb248
|
|
| MD5 |
0bf9e512863d0ee1c6ea71caab82f51c
|
|
| BLAKE2b-256 |
d56218d38e3008d7c5b42780f33ade75476a08cfdcefbefde8e5fb3abe88de87
|
File details
Details for the file b64image-0.1.2-py3-none-any.whl.
File metadata
- Download URL: b64image-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.5 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 |
59dbb6274ed8b2308b8f120473710bfd64a65c5755d7f10d067f2e531ddc655e
|
|
| MD5 |
74a94b5fd28929991b98bcc3e419520c
|
|
| BLAKE2b-256 |
87fe91b84e45cb321bc61685c6eb81c5127408bf7ffa1691f751f6beede03cd0
|