{"id":3224,"library":"pybase62","title":"pybase62","description":"pybase62 is a Python module providing base62 encoding and decoding functionalities. It allows for creating short, URL-safe identifiers, as it avoids special characters like '/' or '=' found in base64. A key advantage is that the alphabetical order of the original data is preserved when encoded, meaning encoded data can be sorted without prior decoding. The current stable version is 1.0.0, released in May 2023, with development tracked on GitHub.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/suminb/base62","tags":["encoding","base62","url-safe","short-ids","data-conversion"],"install":[{"cmd":"pip install pybase62","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Despite the PyPI package name being 'pybase62', the actual module to import is 'base62' due to 'base62' being occupied on PyPI.","wrong":"import pybase62","symbol":"base62 module","correct":"import base62"},{"note":"Directly import the specific functions for clarity.","symbol":"encode, decode, encodebytes, decodebytes","correct":"from base62 import encode, decode, encodebytes, decodebytes"}],"quickstart":{"code":"import base62\n\n# Encode and decode integers\noriginal_int = 34441886726\nencoded_str = base62.encode(original_int)\nprint(f\"Encoded integer {original_int}: {encoded_str}\")\ndecoded_int = base62.decode(encoded_str)\nprint(f\"Decoded string '{encoded_str}': {decoded_int}\")\nassert original_int == decoded_int\n\n# Encode and decode bytes\noriginal_bytes = b'\\x00\\xff\\xff'\nencoded_bytes_str = base62.encodebytes(original_bytes)\nprint(f\"Encoded bytes {original_bytes}: {encoded_bytes_str}\")\ndecoded_bytes = base62.decodebytes(encoded_bytes_str)\nprint(f\"Decoded string '{encoded_bytes_str}': {decoded_bytes}\")\nassert original_bytes == decoded_bytes","lang":"python","description":"This quickstart demonstrates basic integer and byte array encoding and decoding using the `base62` module. It highlights the primary `encode`/`decode` functions for integers and `encodebytes`/`decodebytes` for byte arrays."},"warnings":[{"fix":"Always use `import base62` or `from base62 import ...` after installing `pybase62`.","message":"The PyPI package name is `pybase62`, but the module to import is `base62`. Importing `pybase62` will result in an `ImportError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `bytes` are passed to `encodebytes()` and `str` to `decodebytes()`. They are designed to be commutative: `value_str == encodebytes(decodebytes(value_str))` and `value_bytes == decodebytes(encodebytes(value_bytes))`.","message":"When working with byte arrays, `base62.encodebytes()` expects a `bytes` object as input, while `base62.decodebytes()` expects a `str` object (the encoded string) as input. Misunderstanding these input types can lead to `TypeError` or incorrect results.","severity":"gotcha","affected_versions":"0.2.0 and later"},{"fix":"Stick to a single `base62` library throughout your project to ensure consistent encoding and decoding. If interoperability is required, verify the exact character set and algorithm used by each implementation.","message":"Multiple Python libraries exist for Base62 encoding (e.g., `pybase62`, `base62-py`, `base-62`). These implementations may use different character sets or algorithms, leading to incompatible encoded outputs. An integer encoded with one library might not be correctly decoded by another.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}