Skip to main content

A universal format converter for images and audio files

Project description

Convalt

A Python library for converting between various image and audio formats with a simple, unified API.

Features

  • Single interface for all format conversions
  • Support for popular image formats: PNG, JPEG, GIF, BMP, TIFF, WEBP, ICO
  • Support for popular audio formats: MP3, WAV, OGG, FLAC, M4A, AAC
  • Batch conversion capabilities
  • Automatic handling of format-specific requirements
  • Conversion history tracking
  • Comprehensive error handling

Installation

pip install convalt

For audio conversion support, you also need FFmpeg installed on your system:

Windows: Download from ffmpeg.org

macOS:

brew install ffmpeg

Linux:

sudo apt-get install ffmpeg

Quick Start

from Convalt import Convalt

converter = Convalt()

# Convert image formats
converter.convert("input.png", "output.jpg", quality=90)

# Convert audio formats
converter.convert("song.mp3", "song.wav", bitrate="320k")

# Batch convert multiple files
files = ["image1.png", "image2.png", "image3.png"]
converter.batch_convert(files, "jpg", output_dir="converted")

Usage Examples

Basic Image Conversion

from Convalt import Convalt

converter = Convalt()

# PNG to JPEG
converter.convert("photo.png", "photo.jpg", quality=95)

# JPEG to PNG
converter.convert("image.jpg", "image.png")

# PNG to GIF
converter.convert("animation.png", "animation.gif")

Basic Audio Conversion

# MP3 to WAV
converter.convert("song.mp3", "song.wav", bitrate="320k")

# WAV to MP3
converter.convert("audio.wav", "audio.mp3", bitrate="192k")

# MP3 to OGG
converter.convert("music.mp3", "music.ogg")

Batch Conversion

# Convert multiple images
image_files = ["photo1.png", "photo2.png", "photo3.png"]
converter.batch_convert(
    image_files, 
    "jpg", 
    output_dir="converted",
    quality=85
)

# Convert multiple audio files
audio_files = ["track1.mp3", "track2.mp3"]
converter.batch_convert(
    audio_files,
    "wav",
    output_dir="converted_audio"
)

Advanced Options

# High-quality JPEG with optimization
converter.convert(
    "original.png",
    "output.jpg",
    quality=98,
    optimize=True
)

# Optimized PNG
converter.convert(
    "large.png",
    "optimized.png",
    optimize=True
)

# High-bitrate audio
converter.convert(
    "source.wav",
    "output.mp3",
    bitrate="320k"
)

Error Handling

from Convalt import (
    Convalt, 
    ConversionError, 
    UnsupportedFormatError
)

converter = Convalt()

try:
    converter.convert("input.png", "output.jpg")
except FileNotFoundError:
    print("Input file not found")
except UnsupportedFormatError:
    print("Format conversion not supported")
except ConversionError as e:
    print(f"Conversion failed: {e}")

Check Supported Formats

converter = Convalt()
formats = converter.get_supported_formats()

print("Image formats:", formats['image'])
print("Audio formats:", formats['audio'])

Conversion History

converter = Convalt()

# Perform conversions
converter.convert("image1.png", "image1.jpg")
converter.convert("image2.png", "image2.jpg")

# View history
history = converter.get_history()
for item in history:
    print(f"{item['input_format']}{item['output_format']}")

API Reference

Convalt

convert(input_path, output_path, **kwargs)

Convert a file from one format to another.

Parameters:

  • input_path (str): Path to the input file
  • output_path (str): Path to the output file
  • quality (int): JPEG/WEBP quality, 1-100 (default: 95)
  • optimize (bool): Optimize output file size (default: True)
  • bitrate (str): Audio bitrate, e.g. "192k", "320k" (default: "192k")

Returns: Path to the converted file (str)

Raises:

  • FileNotFoundError: Input file doesn't exist
  • UnsupportedFormatError: Format conversion not supported
  • ConversionError: Conversion failed

batch_convert(input_files, output_format, output_dir=None, **kwargs)

Convert multiple files to the same output format.

Parameters:

  • input_files (list): List of input file paths
  • output_format (str): Target format without dot (e.g., 'png', 'mp3')
  • output_dir (str, optional): Output directory
  • **kwargs: Additional conversion options

Returns: List of output file paths

get_supported_formats()

Get all supported formats by category.

Returns: Dictionary with 'image' and 'audio' keys containing lists of supported formats

get_history()

Get conversion history.

Returns: List of conversion records

Supported Formats

Image Formats

PNG, JPEG, JPG, GIF, BMP, TIFF, WEBP, ICO

Audio Formats

MP3, WAV, OGG, FLAC, M4A, AAC

Requirements

  • Python 3.7+
  • Pillow >= 10.0.0
  • pydub >= 0.25.0
  • FFmpeg (for audio conversion)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Pillow for image processing
  • Built with pydub for audio processing
  • Powered by FFmpeg for audio codec support

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.

Changelog

Version 1.1.0

  • Initial release
  • Image format conversion support
  • Audio format conversion support
  • Batch conversion capabilities
  • Conversion history tracking

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

convalt-1.1.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

convalt-1.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file convalt-1.1.0.tar.gz.

File metadata

  • Download URL: convalt-1.1.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for convalt-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e1ebc5648f7b1e19d517207a6cf27176c004b7837720a69a95eb644390592035
MD5 dd805c111c12ccc2504e912fbbc649d9
BLAKE2b-256 a18caf10f374748db8adcfc5c607a124607ba4ab90470e563ba1998f1811e6e0

See more details on using hashes here.

File details

Details for the file convalt-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: convalt-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for convalt-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ed5d232a7be3a6a026e0853d04ca3397bae33d76b3f15b29ac8373b02bc29b5
MD5 a5e23126ec372c0e4abf17bc7a6828ce
BLAKE2b-256 c0b7c150afb95ce4878342a165383aaeb023f8b2712949b62ede94ffbcc53d89

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