Skip to main content

py-multibase

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_by_name
>>> encoder = Encoder('base64')
>>> encoded1 = encoder.encode('data1')
>>> encoded2 = encoder.encode('data2')

>>> # Or resolve by name or single-character prefix
>>> encoder = encoder_by_name('base64')
>>> encoder = encoder_by_name('m')

>>> 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

Metadata

Release files for py-multibase 2.1.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.1.0
File Size Uploaded Provenance Actions
py_multibase-2.1.0.tar.gz 31.4 kB Without provenance Details for py_multibase-2.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.6 kB

Release files / py_multibase-2.1.0.tar.gz

Download URL py_multibase-2.1.0.tar.gz
Size 31.4 kB
Tags Source
SHA-256 checksum
How to use checksums
645541b8139913ef18cd5576aeaeeca7e142fc937e82359122ff95c3f2e16bdc
BLAKE2b-256 checksum
How to use checksums
459dd6dc9949439e64d7c0c0455a1a8d56aecfd32159d014f94439e65e61b96b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

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

Download URL py_multibase-2.1.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb2b2769f0cfa7fe4d3af61d6d37d3f1163ad8422a2d05d8ca968864e626fc07
BLAKE2b-256 checksum
How to use checksums
0c280140161e3c6940403a7f8168605b8195a956fbbc6052f612d9afc62120b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for py-multibase 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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