Python Base Converter

1.2.2 · maintenance · verified Sat Apr 11

Python-baseconv is a lightweight Python module designed to convert numbers from base 10 integers to base X strings and vice versa. It provides predefined converters for common bases like binary, hexadecimal, and Base64, as well as the ability to define custom alphabets. The current version is 1.2.2, with its last release in April 2019, suggesting a maintenance-focused release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the predefined base converters and how to create a custom BaseConverter with your own alphabet for encoding and decoding integers.

from baseconv import base62, BaseConverter

# Using a predefined converter (e.g., Base62)
encoded_value = base62.encode(1234567890)
print(f"Encoded to Base62: {encoded_value}")
decoded_value = base62.decode(encoded_value)
print(f"Decoded from Base62: {decoded_value}")

# Creating a custom converter
my_alphabet = '0123456789ABCDEF'
my_hex_converter = BaseConverter(my_alphabet)

custom_encoded = my_hex_converter.encode(255)
print(f"Custom Hex Encoded: {custom_encoded}")
custom_decoded = my_hex_converter.decode(custom_encoded)
print(f"Custom Hex Decoded: {custom_decoded}")

view raw JSON →