Skip to main content

Forked from the original author until they incorporate latest fixes; Python library for general Base-N encodings.

Project description

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.

Project details


Download files

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

Source Distribution

makkus.bases-0.2.2.tar.gz (55.4 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file makkus.bases-0.2.2.tar.gz.

File metadata

  • Download URL: makkus.bases-0.2.2.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for makkus.bases-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5fb594b17f863fee5dca09c19c006367b7ea2a005d06b3544213cf30ee5c6d1a
MD5 2576be5d6160246a64f592d7450080e9
BLAKE2b-256 f746c9db4a0cabf1ef4136ddb7631e71aae0d2723c7ecc90f34a1fa03f018cb6

See more details on using hashes here.

File details

Details for the file makkus.bases-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: makkus.bases-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for makkus.bases-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 74b013707e3e685c3d7f6e40a3aef68d590eb1d4c65fb6caae54f23587a488e7
MD5 e7c7cf69c1e64be8ce4df6ee45bb7fef
BLAKE2b-256 92cde70126e6086b91763d3e42adf673ebca7d8e81fec2cf064c7a6c3c385bcf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page