bases: A Python library for Base-N encodings
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
Metadata
Release files for bases 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bases-0.3.0.tar.gz | 790.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bases-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 826.0 kB
Release files / bases-0.3.0.tar.gz
| Download URL | bases-0.3.0.tar.gz |
|---|---|
| Size | 790.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70f04a4a45d63245787f9e89095ca11042685b6b64b542ad916575ba3ccd1570
|
|
BLAKE2b-256 checksum How to use checksums |
de8d105bca352e2fc5f1ee07f425ec296aa680525aac7f197ef135ea057902ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Release files / bases-0.3.0-py3-none-any.whl
| Download URL | bases-0.3.0-py3-none-any.whl |
|---|---|
| Size | 36.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2fef3366f3e522ff473d2e95c21523fe8e44251038d5c6150c01481585ebf5b
|
|
BLAKE2b-256 checksum How to use checksums |
b4157bcf28a3f971e1b0523fab46ae3ca935a589249544187558e5a8e70af393
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Security for bases 0.3.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.