py-multibase is a Python library that provides an implementation of the Multibase protocol. Multibase is designed to distinguish base encodings (like base64, base58btc, etc.) and other simple string encodings, ensuring compatibility across different systems by making the encoding self-describing. The library is currently at version 2.0.0 and is actively maintained, facilitating encoding and decoding of data with various Multibase formats.
pip install py-multibaseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode and decode data using various multibase formats, including `base58btc` and `base64`. It also shows the use of reusable `Encoder` and `Decoder` classes for multiple operations and how to list supported encodings. Remember that `encode` takes `str` or `bytes` and `decode` returns `bytes`, so you might need to convert to `str` for printing.
Upgrade Python to 3.10+ or pin `py-multibase` to a 1.x release: `pip install 'py-multibase<2.0.0'`
Consult the `py-multibase` GitHub repository or documentation for the most up-to-date list of supported encodings. Consider contributing or using alternative libraries for unsupported formats.
Ensure proper type handling: encode strings to bytes before passing to `encode` if implicit conversion isn't desired, and always `decode()` the output of `multibase.decode` if a `str` is required.
Install the library using pip: `pip install py-multibase`
Convert your string to bytes before passing it to the function: `my_string.encode('utf-8')`. Example: `encode('base64', 'hello world'.encode('utf-8'))` or ensure the function handles string input if it's designed to.Use a valid multibase name as defined in the Multibase specification and supported by `py-multibase`. You can use `multibase.list_encodings()` to see all supported options.