Skip to main content
https://img.shields.io/pypi/v/py-multibase.svg https://github.com/multiformats/py-multibase/actions/workflows/tox.yml/badge.svg Documentation Status

Multibase implementation for Python

Multibase is a protocol for distinguishing base encodings and other simple string encodings, and for ensuring full compatibility with program interfaces.

It answers the question: Given data d encoded into string s, how can I tell what base d is encoded with?

Base encodings exist because transports have restrictions, use special in-band sequences, or must be human-friendly. When systems chose a base to use, it is not always clear which base to use, as there are many tradeoffs in the decision. Multibase is here to save programs and programmers from worrying about which encoding is best.

It solves the biggest problem: a program can use multibase to take input or produce output in whichever base is desired.

The important part is that the value is self-describing, letting other programs elsewhere know what encoding it is using.

Installation

$ pip install py-multibase

Sample Usage

>>> # encoding a buffer
>>> from multibase import encode, decode
>>> encode('base58btc', 'hello world')
b'zStV1DL6CwTryKyV'
>>> encode('base64', 'hello world')
b'mGhlbGxvIHdvcmxk'
>>> # decoding a multibase
>>> decode('mGhlbGxvIHdvcmxk')
b'hello world'
>>> decode(b'zStV1DL6CwTryKyV')
b'hello world'
>>> decode(encode('base2', b'hello world'))
b'hello world'

>>> # Using reusable Encoder/Decoder classes
>>> from multibase import Encoder, Decoder
>>> encoder = Encoder('base64')
>>> encoded1 = encoder.encode('data1')
>>> encoded2 = encoder.encode('data2')

>>> decoder = Decoder()
>>> decoded = decoder.decode(encoded1)

>>> # Getting encoding information
>>> from multibase import get_encoding_info, list_encodings, is_encoding_supported
>>> info = get_encoding_info('base64')
>>> print(info.encoding, info.code)
base64 b'm'
>>> all_encodings = list_encodings()
>>> is_encoding_supported('base64')
True

>>> # Decode with encoding return
>>> encoding, data = decode(encoded1, return_encoding=True)
>>> print(f'Encoded with {encoding}: {data}')

Supported codecs

  • base2

  • base8

  • base10

  • base16

  • base16upper

  • base32hex

  • base32hexupper

  • base32hexpad

  • base32hexpadupper

  • base32

  • base32upper

  • base32pad

  • base32padupper

  • base32z

  • base36

  • base36upper

  • base58flickr

  • base58btc

  • base64

  • base64pad

  • base64url

  • base64urlpad

  • base256emoji

Release files for py-multibase 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-multibase 2.0.0
File Size Uploaded
py_multibase-2.0.0.tar.gz 26.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-multibase 2.0.0
File Interpreter ABI Platform
py_multibase-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.5 kB

Release files / py_multibase-2.0.0.tar.gz

Download URL py_multibase-2.0.0.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
58c1a264195fa1ae29ea707c6fc8196446f4bdb92e0f9a0f131e0f280b238839
BLAKE2b-256 checksum
How to use checksums
bc525ed393ab49df7e3b03995d3c4e53bae1e8c2ca40909cf25a41b346c09a38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.4

Release files / py_multibase-2.0.0-py3-none-any.whl

Download URL py_multibase-2.0.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b29ce489b556134e73998a11712c406b70950812955df64084754e0774e40900
BLAKE2b-256 checksum
How to use checksums
36c738035079d9978b32b962f996f1cccaa166ecfe38723ab4349ab32166c037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.4

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page