Registry / serialization / pybase62

pybase62

JSON →
library1.0.0pypypi✓ verified 26d ago

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.

pip install pybase62
INSTALL
IMPORT
SIG · PYBASE62
P
pybase62
serializationpythonv1.0.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · 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 · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

base62 module
import base62
import pybase62
Despite the PyPI package name being 'pybase62', the actual module to import is 'base62' due to 'base62' being occupied on PyPI.
encode, decode, encodebytes, decodebytes
from base62 import encode, decode, encodebytes, decodebytes
Directly import the specific functions for clarity.

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.

import base62 # Encode and decode integers original_int = 34441886726 encoded_str = base62.encode(original_int) print(f"Encoded integer {original_int}: {encoded_str}") decoded_int = base62.decode(encoded_str) print(f"Decoded string '{encoded_str}': {decoded_int}") assert original_int == decoded_int # Encode and decode bytes original_bytes = b'\x00\xff\xff' encoded_bytes_str = base62.encodebytes(original_bytes) print(f"Encoded bytes {original_bytes}: {encoded_bytes_str}") decoded_bytes = base62.decodebytes(encoded_bytes_str) print(f"Decoded string '{encoded_bytes_str}': {decoded_bytes}") assert original_bytes == decoded_bytes
pybase62 --version
Debug
Known issues
gotchaThe PyPI package name is `pybase62`, but the module to import is `base62`. Importing `pybase62` will result in an `ImportError`.
fix
Always use `import base62` or `from base62 import ...` after installing `pybase62`.
affects: All versions
gotchaWhen 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.
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))`.
affects: 0.2.0 and later
gotchaMultiple 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.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'base62'
The Python package for base62 encoding is installed as `pybase62`, but the module name to import in your code is `base62`.
fix
Install the package using `pip install pybase62` and then import it in your code using `import base62`.
TypeError: an integer is required (got type bytes)
The `base62.encode()` function expects an integer as input, but a `bytes` object was passed instead.
fix
Use the `base62.encodebytes()` function for encoding `bytes` objects, or convert your bytes object to an integer before passing it to `base62.encode()`.
TypeError: a string is required (got type bytes)
The `base62.decodebytes()` function expects a string as input (the base62 encoded string), but a `bytes` object was provided.
fix
Ensure the input to `base62.decodebytes()` is a `str` type. If you have a `bytes` object that needs to be decoded, first convert it to a string (e.g., `my_bytes.decode('ascii')`).
AttributeError: module 'base62' has no attribute 'encodebytes'
This error occurs when trying to use `encodebytes` or `decodebytes` with an older version of the `pybase62` library (prior to version 0.2.0), which did not include these functions.
fix
Upgrade the `pybase62` package to the latest version using `pip install --upgrade pybase62`.
Upgrade
Version history
1.0.0latest on PyPI · released May 29, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
pybase62 — pip install pybase62 · libregistry