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.0.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.0.0.tar.gz (19.3 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.0.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for convalt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 333ef224204aa62596a1e197cf90464ff452efc4291e95740f5f9a5945004a4d
MD5 4063fde3529a4527bec6c84fbb00345a
BLAKE2b-256 f8f90a49e3d0b46448a1fe05e9d0c60c0909bbb68f7872870f0905ab4af8b837

See more details on using hashes here.

File details

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

File metadata

  • Download URL: convalt-1.0.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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac1bcfeb0df87310d4b2a463abb4534cfa73858cc964bcbb8d5a439e983b534d
MD5 cc19e4ee708c1d94f25224c85915ddfb
BLAKE2b-256 51606326b09ee0a71d139dae6b4ccd5d01473012656fb32e8441746d6c9d7425

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