{"id":8461,"library":"py-multibase","title":"py-multibase","description":"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.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/multiformats/py-multibase","tags":["multibase","encoding","decoding","multiformats","baseN","cryptography"],"install":[{"cmd":"pip install py-multibase","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides core base encoding implementations used by multibase.","package":"bases","optional":false}],"imports":[{"symbol":"encode, decode","correct":"from multibase import encode, decode"},{"symbol":"Encoder, Decoder","correct":"from multibase import Encoder, Decoder"},{"symbol":"get_encoding_info, list_encodings","correct":"from multibase import get_encoding_info, list_encodings"}],"quickstart":{"code":"from multibase import encode, decode, list_encodings\n\n# Encode a string to base58btc\ndata_to_encode = 'hello world'\nencoded_base58 = encode('base58btc', data_to_encode)\nprint(f\"Encoded (base58btc): {encoded_base58}\")\n\n# Encode a string to base64\nencoded_base64 = encode('base64', data_to_encode)\nprint(f\"Encoded (base64): {encoded_base64}\")\n\n# Decode a multibase string\ndecoded_data = decode(encoded_base64)\nprint(f\"Decoded: {decoded_data.decode('utf-8')}\")\n\n# Using reusable Encoder/Decoder classes\nfrom multibase import Encoder, Decoder\nbase64_encoder = Encoder('base64')\nencoded_reusable = base64_encoder.encode(b'reusable data')\nprint(f\"Encoded (reusable base64): {encoded_reusable}\")\n\ndecoder = Decoder()\ndecoded_reusable = decoder.decode(encoded_reusable)\nprint(f\"Decoded (reusable): {decoded_reusable.decode('utf-8')}\")\n\n# List available encodings\n# print(list_encodings())","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python to 3.10+ or pin `py-multibase` to a 1.x release: `pip install 'py-multibase<2.0.0'`","message":"Version 2.0.0 and higher of `py-multibase` requires Python 3.10 or newer. Users on older Python versions (e.g., 3.9 or earlier) must remain on `py-multibase` 1.x or upgrade their Python interpreter.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"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.","message":"Not all multibase encodings from the official specification may be fully implemented in `py-multibase` 2.0.0. GitHub issues indicate ongoing work to achieve 100% compatibility with reference implementations. Verify support for specific or less common encodings if they are critical to your application.","severity":"gotcha","affected_versions":"2.0.0"},{"fix":"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.","message":"The `encode` function can accept both string and bytes input, but `decode` always returns `bytes`. Attempting to treat `bytes` output directly as a Python `str` without explicit decoding (e.g., `.decode('utf-8')`) will lead to `TypeError` or unexpected behavior.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install py-multibase`","cause":"The `py-multibase` library is either not installed or not available in the current Python environment.","error":"ModuleNotFoundError: No module named 'multibase'"},{"fix":"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.","cause":"You are passing a Python string to a function (e.g., `multibase.encode`) that expects `bytes` or a bytes-like object, without explicitly encoding the string first.","error":"TypeError: a bytes-like object is required, not 'str'"},{"fix":"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.","cause":"The specified multibase encoding (e.g., 'some_invalid_base') is not recognized or supported by the library.","error":"ValueError: Unknown multibase encoding: 'some_invalid_base'"}]}