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-baseconvVerified import paths — ran on the pinned version, not inferred.
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.
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.
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`.
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.
Install the package using pip: `pip install python-baseconv`
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).
Provide an integer as the first argument to `base_encode`, for example: `baseconv.base10.encode(123)`
Ensure the input to `base_decode` is a string, for example: `baseconv.base10.decode('123')`No dependency data recorded yet.