Registry / serialization / base58

base58

JSON →
library2.1.1pypypi✓ verified 24d ago

The `base58` library provides an implementation of Base58 and Base58Check encoding and decoding, compatible with schemes used by the Bitcoin network. It also supports custom alphabets, such as the XRP one. The current version is 2.1.1, and the library has a stable release history with periodic updates to address compatibility and features.

pip install base58
INSTALL
IMPORT
SIG · BASE58
B
base58
serializationpythonv2.1.1
Install
1.6s avg
Import
14ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.1 · 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.014s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

b58encode
from base58 import b58encode
import base58
b58decode
from base58 import b58decode
import base58
b58encode_check
from base58 import b58encode_check
import base58

Demonstrates basic Base58 encoding and decoding, including the Base58Check functionality and using a custom alphabet like XRP's. It's crucial to work with byte strings for all encoding/decoding operations.

import base58 # Encode binary data data_bytes = b'hello world' encoded_data = base58.b58encode(data_bytes) print(f"Encoded: {encoded_data.decode('ascii')}") # Decode Base58 string back to bytes decoded_bytes = base58.b58decode(encoded_data) print(f"Decoded: {decoded_bytes.decode('utf-8')}") # Encode with Base58Check (includes a checksum) data_for_check = b'my secret data' encoded_check = base58.b58encode_check(data_for_check) print(f"Encoded (with check): {encoded_check.decode('ascii')}") # Decode Base58Check (verifies checksum) decoded_check = base58.b58decode_check(encoded_check) print(f"Decoded (with check): {decoded_check.decode('utf-8')}") # Using a custom alphabet (e.g., XRP/Ripple) xrp_data = b'xrp address seed' encoded_xrp = base58.b58encode(xrp_data, alphabet=base58.XRP_ALPHABET) print(f"Encoded (XRP alphabet): {encoded_xrp.decode('ascii')}")
base58 --version
Debug
Known issues
breakingPython 2 support was dropped in version 2.0.0. Projects still on Python 2 must use the 1.x series, which will not receive new features.
fix
Upgrade to Python 3.5+ to use base58 >= 2.0.0. If unable to upgrade Python, pin to base58<2.0.0.
affects: >=2.0.0
gotchaEncoding and decoding functions (`b58encode`, `b58decode`, etc.) strictly expect bytes-like objects as input. Passing a plain Python string will result in errors or incorrect encoding.
fix
Always convert string inputs to bytes (e.g., `my_string.encode('utf-8')`) before passing them to `base58` functions. Similarly, if you need a string output, decode the resulting bytes (e.g., `encoded_bytes.decode('ascii')`).
affects: All versions
gotchaWhen decoding, the input string must strictly adhere to the Base58 character set. The library's decoding functions will raise a `ValueError` if invalid characters (e.g., '0', 'O', 'I', 'l' which are excluded from Base58) are present.
fix
Ensure input strings for decoding are valid Base58. Implement robust error handling (e.g., `try-except ValueError`) when processing external or untrusted Base58 strings.
affects: All versions
gotchaIf using custom alphabets (e.g., `base58.XRP_ALPHABET`), ensure that the *exact same alphabet* is used for both encoding and subsequent decoding. Mismatched alphabets will lead to `ValueError` or corrupted data.
fix
Explicitly pass the `alphabet` parameter to both `b58encode` and `b58decode` functions to guarantee consistency, especially when dealing with data from different systems.
affects: All versions
gotchaWhen dealing with Base58Check, the checksum calculation (typically a double SHA-256 hash) and its inclusion are crucial. Manually implementing this can be prone to errors in hashing or byte extraction.
fix
Always use `base58.b58encode_check()` and `base58.b58decode_check()` for Base58Check operations to leverage the library's correct handling of checksums. Avoid manual checksum computations where possible with this library.
affects: All versions
Upgrade
Version history
2.1.1latest on PyPI · released Oct 30, 2021
Audit
Dependencies
PythonrequiredRequires Python 3.5 or higher for versions 2.x.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
base58 — pip install base58 · libregistry