Official Convertorio SDK for Python - Convert images easily with a simple API
Project description
Convertorio SDK for Python
Official Python SDK for the Convertorio API. Convert images between 20+ formats with just a few lines of code.
Features
- ✅ Simple, intuitive API
- ✅ Event-driven progress tracking
- ✅ Automatic file upload and download
- ✅ Support for 20+ image formats
- ✅ Type hints included
- ✅ Batch conversion support
- ✅ Full error handling
Installation
pip install convertorio-sdk
Quick Start
from convertorio_sdk import ConvertorioClient
# Initialize the client
client = ConvertorioClient(
api_key='your_api_key_here' # Get your API key from https://convertorio.com/account
)
# Convert an image
result = client.convert_file(
input_path='./image.png',
target_format='jpg'
)
print(f"Converted! {result['output_path']}")
Configuration
Creating a Client
from convertorio_sdk import ConvertorioClient
client = ConvertorioClient(
api_key='your_api_key_here', # Required: Your API key
base_url='https://api.convertorio.com' # Optional: Custom API URL
)
Getting your API Key:
- Sign up at convertorio.com
- Go to your Account Settings
- Generate an API key
API Reference
convert_file()
Convert an image file from one format to another.
Parameters:
input_path(str, required): Path to the input image filetarget_format(str, required): Target format (jpg, png, webp, avif, gif, bmp, tiff, ico, heic, etc.)output_path(str, optional): Custom output path. If not provided, uses the same directory as input with new extensionconversion_metadata(dict, optional): Advanced conversion options (see Advanced Options section below)
Returns: dict
Example:
result = client.convert_file(
input_path='./photo.png',
target_format='webp',
output_path='./converted/photo.webp'
)
print(result)
# {
# 'success': True,
# 'job_id': 'abc-123-def',
# 'input_path': './photo.png',
# 'output_path': './converted/photo.webp',
# 'source_format': 'png',
# 'target_format': 'webp',
# 'file_size': 45620,
# 'processing_time': 1250,
# 'download_url': 'https://...'
# }
get_account()
Get account information including points balance and usage.
Returns: dict
Example:
account = client.get_account()
print(account)
# {
# 'id': 'user-123',
# 'email': 'user@example.com',
# 'name': 'John Doe',
# 'plan': 'free',
# 'points': 100,
# 'daily_conversions_remaining': 5,
# 'total_conversions': 42
# }
list_jobs()
List your conversion jobs with optional filtering.
Parameters:
limit(int, optional): Number of jobs to return (default: 50, max: 100)offset(int, optional): Offset for pagination (default: 0)status(str, optional): Filter by status ('completed', 'failed', 'processing', etc.)
Returns: list[dict]
Example:
jobs = client.list_jobs(limit=10, status='completed')
print(jobs)
# [
# {
# 'id': 'job-123',
# 'status': 'completed',
# 'original_filename': 'photo.png',
# 'source_format': 'png',
# 'target_format': 'jpg',
# 'processing_time_ms': 1200,
# 'created_at': '2025-01-20T10:30:00Z'
# },
# ...
# ]
get_job()
Get details for a specific conversion job.
Parameters:
job_id(str, required): The job ID
Returns: dict
Example:
job = client.get_job('job-123')
print(job)
# {
# 'id': 'job-123',
# 'status': 'completed',
# 'original_filename': 'photo.png',
# 'download_url': 'https://...',
# ...
# }
Events
The client supports event callbacks for tracking conversion progress:
Event: start
Emitted when conversion starts.
def on_start(data):
print(f"Starting: {data['file_name']}")
print(f"Converting {data['source_format']} to {data['target_format']}")
client.on('start', on_start)
Event: progress
Emitted at each step of the conversion process.
def on_progress(data):
print(f"Step: {data['step']}")
print(f"Message: {data['message']}")
# data['step'] can be:
# - 'requesting-upload-url'
# - 'uploading'
# - 'confirming'
# - 'converting'
# - 'downloading'
client.on('progress', on_progress)
Event: status
Emitted during polling for job completion.
def on_status(data):
print(f"Status: {data['status']}")
print(f"Attempt: {data['attempt']}/{data['max_attempts']}")
client.on('status', on_status)
Event: complete
Emitted when conversion completes successfully.
def on_complete(result):
print('Conversion complete!')
print(f"Output: {result['output_path']}")
print(f"Size: {result['file_size']} bytes")
print(f"Time: {result['processing_time']} ms")
client.on('complete', on_complete)
Event: error
Emitted when an error occurs.
def on_error(data):
print(f"Conversion failed: {data['error']}")
client.on('error', on_error)
Supported Formats
The SDK supports conversion between all formats supported by Convertorio:
Common Formats:
- JPG/JPEG
- PNG
- WebP
- AVIF
- GIF
- BMP
- TIFF
Advanced Formats:
- HEIC/HEIF (iPhone photos)
- ICO (icons)
- SVG (vectors)
- RAW formats (CR2, NEF, DNG)
- PSD (Photoshop)
- AI (Adobe Illustrator)
- EPS
- JXL (JPEG XL)
Advanced Conversion Options
The SDK supports advanced conversion options through the conversion_metadata parameter. This allows you to control aspect ratio, quality, resize dimensions, and more.
Aspect Ratio Control
Transform images to specific aspect ratios with automatic cropping or padding.
Available Aspect Ratios:
original- Keep original aspect ratio (default)1:1- Square (Instagram, profile pictures)4:3- Traditional photos16:9- Widescreen, YouTube thumbnails9:16- Vertical video, Stories21:9- Ultrawide- Custom ratios like
16:10,3:2, etc.
Crop Strategies:
fit- Add padding (letterbox/pillarbox) to maintain entire imagecrop-center- Crop from center (default)crop-top- Crop from topcrop-bottom- Crop from bottomcrop-left- Crop from leftcrop-right- Crop from right
Example:
result = client.convert_file(
input_path='./photo.jpg',
target_format='jpg',
conversion_metadata={
'aspect_ratio': '16:9',
'crop_strategy': 'crop-center'
}
)
Quality Control
Adjust compression quality for lossy formats (JPG, WebP, AVIF, HEIC).
Quality Range: 1-100
- 1 = Lowest quality, smallest file size
- 100 = Highest quality, largest file size
- Default: 85 (recommended balance)
Quality Guidelines:
- 95-100: Professional photography, archival
- 85-94: High quality for web (recommended)
- 70-84: Good quality, smaller files
- 50-69: Medium quality, significant compression
- 1-49: Low quality, maximum compression
Example:
result = client.convert_file(
input_path='./photo.jpg',
target_format='webp',
conversion_metadata={
'quality': 90
}
)
ICO Format Options
Create Windows icons with specific pixel sizes.
Available Sizes: 16, 32, 48, 64, 128, 256
The image will be automatically cropped to square using the selected crop strategy.
Example:
result = client.convert_file(
input_path='./logo.png',
target_format='ico',
conversion_metadata={
'icon_size': 64,
'crop_strategy': 'crop-center'
}
)
Resize Control
Resize images to specific dimensions while optionally maintaining aspect ratio.
Parameters:
resize_width- Target width in pixels (1-10000)resize_height- Target height in pixels (1-10000)
Resize Behavior:
- Width only: Height calculated automatically (maintains aspect ratio)
- Height only: Width calculated automatically (maintains aspect ratio)
- Both specified: Exact dimensions (may distort image if aspect ratio differs)
Example - Resize by width:
result = client.convert_file(
input_path='./photo.jpg',
target_format='jpg',
conversion_metadata={
'resize_width': 800 # Height will be calculated automatically
}
)
Example - Resize by height:
result = client.convert_file(
input_path='./photo.jpg',
target_format='jpg',
conversion_metadata={
'resize_height': 600 # Width will be calculated automatically
}
)
Example - Resize to exact dimensions:
result = client.convert_file(
input_path='./photo.jpg',
target_format='jpg',
conversion_metadata={
'resize_width': 1920,
'resize_height': 1080 # May distort if original aspect ratio differs
}
)
Example - Combine resize with aspect ratio:
# Create a 500x500 square thumbnail with center crop
result = client.convert_file(
input_path='./photo.jpg',
target_format='jpg',
conversion_metadata={
'aspect_ratio': '1:1',
'crop_strategy': 'crop-center',
'resize_width': 500,
'quality': 90
}
)
Resize Guidelines:
- Use width/height resize for responsive images
- Combine with aspect ratio for precise control
- Quality parameter affects lossy formats (JPG, WebP, AVIF)
- LANCZOS resampling ensures high-quality results
Examples
Basic Conversion
from convertorio_sdk import ConvertorioClient
client = ConvertorioClient(api_key='your_api_key_here')
result = client.convert_file(
input_path='./input.png',
target_format='jpg'
)
print(f"Done! {result['output_path']}")
With Progress Events
from convertorio_sdk import ConvertorioClient
client = ConvertorioClient(api_key='your_api_key_here')
def on_progress(data):
print(f"[{data['step']}] {data['message']}")
def on_complete(result):
print('✓ Conversion completed!')
print(f"Output: {result['output_path']}")
client.on('progress', on_progress)
client.on('complete', on_complete)
result = client.convert_file(
input_path='./photo.png',
target_format='webp'
)
Batch Conversion
from pathlib import Path
from convertorio_sdk import ConvertorioClient
client = ConvertorioClient(api_key='your_api_key_here')
# Get all PNG files
images_dir = Path('./images')
png_files = list(images_dir.glob('*.png'))
# Convert all to WebP
for file_path in png_files:
result = client.convert_file(
input_path=str(file_path),
target_format='webp'
)
print(f'Converted: {file_path}')
Advanced Conversion with Metadata
from convertorio_sdk import ConvertorioClient
client = ConvertorioClient(api_key='your_api_key_here')
# Convert to 16:9 aspect ratio with high quality
result = client.convert_file(
input_path='./photo.jpg',
target_format='webp',
conversion_metadata={
'aspect_ratio': '16:9',
'crop_strategy': 'crop-center',
'quality': 90
}
)
print(f"Converted to 16:9: {result['output_path']}")
Error Handling
from convertorio_sdk import ConvertorioClient, ConversionError
client = ConvertorioClient(api_key='your_api_key_here')
try:
result = client.convert_file(
input_path='./image.png',
target_format='jpg'
)
print(f"Success: {result['output_path']}")
except FileNotFoundError as e:
print('Input file does not exist')
except ConversionError as e:
print(f'Conversion failed: {e}')
# Handle specific errors
if 'Insufficient' in str(e):
print('Not enough points/credits')
Rate Limiting
The API has the following rate limits:
- 1 request per second per IP address
- 5 concurrent jobs maximum per user
The SDK automatically handles rate limiting by polling job status with appropriate delays.
Error Handling
Common errors you might encounter:
| Error | Description | Solution |
|---|---|---|
ValueError: API key is required |
No API key provided | Provide your API key in the constructor |
FileNotFoundError |
File doesn't exist | Check the file path |
ConversionError: Invalid API key |
Wrong or expired API key | Verify your API key in account settings |
ConversionError: Insufficient credits |
Not enough points | Purchase more points or use free tier |
ConversionError: File size exceeds limit |
File too large | Maximum file size is 20 MB |
ConversionError: Conversion timeout |
Job took too long | Try again or contact support |
Best Practices
- Reuse the client instance - Don't create a new client for each conversion
- Use events for long conversions - Monitor progress instead of just waiting
- Handle errors gracefully - Always wrap conversions in try/except
- Respect rate limits - Use batch processing with delays if converting many files
- Check file sizes - Maximum file size is 20 MB
- Validate formats - Check that the target format is supported
Support
- Documentation: https://convertorio.com/docs
- API Reference: https://convertorio.com/api-docs
- Support: support@convertorio.com
- GitHub Issues: https://github.com/convertorio/sdk/issues
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
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
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 convertorio_sdk-1.2.0.tar.gz.
File metadata
- Download URL: convertorio_sdk-1.2.0.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f54cce6c4f3581715bd77b67236f231573d11d9f460ac0d65ba16ca1d8c74d
|
|
| MD5 |
46900197fa5b84d3f586882d1a9c8ebe
|
|
| BLAKE2b-256 |
bbc73b84ed13c765c006a4b00397374bc7f63b3e63945f89a7da25b3755b3990
|
File details
Details for the file convertorio_sdk-1.2.0-py3-none-any.whl.
File metadata
- Download URL: convertorio_sdk-1.2.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
544ee54454b17f4a1af5f8188646cd48eaa67ff738227763e5026ee9ed674870
|
|
| MD5 |
e6ec69c3416a7ab2483ea33d4f796628
|
|
| BLAKE2b-256 |
3079c59d90cf2347153bedfb02c435e04776453084f144ac5e8d5578c5d5c5af
|