Registry / serialization / python-baseconv

python-baseconv

JSON →
library1.2.2pypypi✓ verified 25d ago

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.

pip install python-baseconv
INSTALL
IMPORT
SIG · PYTHON-BASECONV
P
python-baseconv
serializationpythonv1.2.2
Install
2.6s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

base2, base16, base36, base56, base58, base62, base64
from baseconv import base2, base16, base36, base56, base58, base62, base64
import baseconv.base64
Predefined converters are directly imported from the `baseconv` package, not as submodules of `baseconv` itself.
BaseConverter
from baseconv import BaseConverter

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}")
Debug
Known issues
gotchaThe library was originally developed with Python 2.7 in mind, as evidenced by Python 2.7 classifiers on PyPI and use of 'L' suffix for long integers in older examples. While the core functionality generally works in Python 3, active Python 3-specific maintenance might be limited.
fix
Ensure your code handles large integers without the 'L' suffix. Test thoroughly in your target Python 3 environment. For new projects, consider alternatives if Python 2 compatibility is a concern or if you need newer Python features/idioms.
affects: <=1.2.2
deprecatedDo not confuse `python-baseconv` with `django.utils.baseconv`. The latter was a private, undocumented module within Django that borrowed code from `python-baseconv` but has been deprecated in Django 4.0 and completely removed in Django 5.0. Directly importing `django.utils.baseconv` will fail in modern Django versions.
fix
If you need base conversion outside of specific Django signing utilities, use the standalone `python-baseconv` library. For Django-specific signing, refer to `django.core.signing`.
affects: Django >= 4.0 (deprecated), Django >= 5.0 (removed)
gotchaThe `BaseConverter` class and its methods (`encode`, `decode`) will raise `ValueError` for invalid inputs, such as an empty digit alphabet during instantiation, using a sign character within the digit alphabet, or encountering digits during decoding that are not present in the converter's alphabet.
fix
Always provide a valid, non-empty alphabet to `BaseConverter` and ensure the sign character is not part of the alphabet. Implement error handling (e.g., `try-except ValueError`) when decoding user-provided or external base-encoded strings.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'baseconv'
The 'baseconv' package is not installed in the current Python environment.
fix
Install the package using pip: `pip install python-baseconv`
ValueError: Found non-alphabet character in input string
The input string provided to a `base_decode` function contains characters that are not part of the specified alphabet for that base converter.
fix
Ensure the input string exclusively uses characters defined in the alphabet of the chosen base converter, or use a converter that supports the required characters (e.g., `baseconv.base62` for typical alphanumeric strings).
TypeError: 'str' object cannot be interpreted as an integer
The `base_encode` function was called with a string as its first argument (the number to encode), but it expects an integer.
fix
Provide an integer as the first argument to `base_encode`, for example: `baseconv.base10.encode(123)`
TypeError: expected string or bytes-like object
The `base_decode` function was called with a non-string type (such as an integer) as its first argument, but it expects a string to decode.
fix
Ensure the input to `base_decode` is a string, for example: `baseconv.base10.decode('123')`
Upgrade
Version history
1.2.2latest on PyPI · released Apr 4, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
python-baseconv — pip install python-baseconv · libregistry