{"id":4218,"library":"python-baseconv","title":"Python Base Converter","description":"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.","status":"maintenance","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/semente/python-baseconv","tags":["base-conversion","numbers","math","utility","encoding","decoding"],"install":[{"cmd":"pip install python-baseconv","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Predefined converters are directly imported from the `baseconv` package, not as submodules of `baseconv` itself.","wrong":"import baseconv.base64","symbol":"base2, base16, base36, base56, base58, base62, base64","correct":"from baseconv import base2, base16, base36, base56, base58, base62, base64"},{"symbol":"BaseConverter","correct":"from baseconv import BaseConverter"}],"quickstart":{"code":"from baseconv import base62, BaseConverter\n\n# Using a predefined converter (e.g., Base62)\nencoded_value = base62.encode(1234567890)\nprint(f\"Encoded to Base62: {encoded_value}\")\ndecoded_value = base62.decode(encoded_value)\nprint(f\"Decoded from Base62: {decoded_value}\")\n\n# Creating a custom converter\nmy_alphabet = '0123456789ABCDEF'\nmy_hex_converter = BaseConverter(my_alphabet)\n\ncustom_encoded = my_hex_converter.encode(255)\nprint(f\"Custom Hex Encoded: {custom_encoded}\")\ncustom_decoded = my_hex_converter.decode(custom_encoded)\nprint(f\"Custom Hex Decoded: {custom_decoded}\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"<=1.2.2"},{"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`.","message":"Do 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.","severity":"deprecated","affected_versions":"Django >= 4.0 (deprecated), Django >= 5.0 (removed)"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}