Skip to main content
Python versions PyPI version PyPI status Checked with Mypy Documentation Status Python package status standard-readme compliant

Bases provides a customisable, parametric implementation of several common styles of Base-N encoding, covering all cases appearing in the multibase specification (except for proquints).

Install

You can install the latest release from PyPI as follows:

$ pip install --upgrade bases

Usage

We suggest you import bases as follows:

>>> import bases

Below are some basic usage examples, to get you started: for detailed documentation, see https://bases.readthedocs.io/

Base encoding objects

>>> from bases import base32
>>> base32
FixcharBaseEncoding(
    StringAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
                   case_sensitive=False),
    pad_char='=', padding='include')

Encoding

>>> b = bytes([70, 98, 190, 187, 66, 224, 178])
>>> base32.encode(b)
'IZRL5O2C4CZA===='

Decoding

>>> s = 'IZRL5O2C4CZA===='
>>> base32.decode(s)
b'Fb\xbe\xbbB\xe0\xb2'
>>> list(base32.decode(s))
[70, 98, 190, 187, 66, 224, 178]

Case/padding variations

>>> b = bytes([70, 98, 190, 187, 66, 224, 178])
>>> base32.encode(b)
'IZRL5O2C4CZA===='
>>> base32lower = base32.lower()
>>> base32lower
FixcharBaseEncoding(
    StringAlphabet('abcdefghijklmnopqrstuvwxyz234567',
                   case_sensitive=False),
    pad_char='=', padding='include')
>>> base32lower.encode(b)
'izrl5o2c4cza===='
>>> base32nopad = base32.nopad()
>>> base32nopad.encode(b)
'IZRL5O2C4CZA'

Case sensitivity variations

>>> s = 'IZRL5O2C4CZA===='
>>> base32lower.decode(s)
b'Fb\xbe\xbbB\xe0\xb2'
>>> base32lower_casesensitive = base32lower.with_case_sensitivity(True)
>>> base32lower_casesensitive.decode(s)
bases.encoding.errors.NonAlphabeticCharError: Invalid character 'I'
encountered for alphabet StringAlphabet('abcdefghijklmnopqrstuvwxyz234567').

Custom base encodings

>>> base4 = bases.make("0123", kind="zeropad-enc", block_nchars=4)
>>> base4
ZeropadBaseEncoding(StringAlphabet('0123'), block_nchars=4)

API

For the full API documentation, see https://bases.readthedocs.io/

Contributing

Please see CONTRIBUTING.md.

License

MIT © Hashberg Ltd.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bases-0.2.1.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bases-0.2.1-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file bases-0.2.1.tar.gz.

File metadata

  • Download URL: bases-0.2.1.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.7

File hashes

Hashes for bases-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b0999e14725b59bff38974b00e918629e0e29f3d80a40e022c6f0f8d5cdff9d4
MD5 48b5c32f197335911042d9c5f2dd3de4
BLAKE2b-256 4930bdd7f0d7c4c34dac9b932c4fa5de0459af00f53a06e042445f80da3bcc7e

See more details on using hashes here.

File details

Details for the file bases-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: bases-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.7

File hashes

Hashes for bases-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d030b5e349773ad2a067bfaaf3a9794b70d23a1f923033c15c2e0ce869854f6d
MD5 3a7f7fb9c676fca5e542bac85cf41123
BLAKE2b-256 74d5b0e135bd2fd2f63a71ddf79583e700a5ba140b636d111ec8f84dfba8af11

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.1 This release

2 files

0.2.0.post1

2 files

0.1.1.post5

2 files

0.1.1.post3

2 files

0.1.0.post2

2 files

0.1.0.post1

2 files

0.1.0

2 files

0.0.0

2 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