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

This is a temporary fork of the original project to be used until the original project incorporates a bug fix to work with newer versions of the ‘typing_extensions’ dependency.

Bug: https://github.com/hashberg-io/typing-validation/issues/1

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.

Metadata

Release files for makkus.bases 0.2.4

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

Source distribution (sdist)

Source distribution for makkus.bases 0.2.4
File Size Uploaded
makkus.bases-0.2.4.tar.gz 55.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for makkus.bases 0.2.4
File Interpreter ABI Platform
makkus.bases-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 91.3 kB

Release files / makkus.bases-0.2.4.tar.gz

Download URL makkus.bases-0.2.4.tar.gz
Size 55.4 kB
Tags Source
SHA-256 checksum
How to use checksums
46c9b1c5a104f6bd94183f9a9d4f28466657970479fb3194bf5d9c298100e6a8
BLAKE2b-256 checksum
How to use checksums
5ac89f50bf8011966dda46d00ab97a14a868756265cd691c3b524f3702af3ef8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / makkus.bases-0.2.4-py3-none-any.whl

Download URL makkus.bases-0.2.4-py3-none-any.whl
Size 35.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e2b519ce3c0bd7fef587f1474b735487388378cc511954236b4343aeb98f059
BLAKE2b-256 checksum
How to use checksums
1c2a916b36830a472621bfaa8729bfea975de1471e306a4743a503e1bcc6c94d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

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