bases


Namebases JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/hashberg-io/bases
SummaryPython library for general Base-N encodings.
upload_time2021-12-30 18:32:13
maintainer
docs_urlNone
authorhashberg
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            bases: A Python library for Base-N encodings
============================================

.. image:: https://img.shields.io/badge/python-3.7+-green.svg
    :target: https://docs.python.org/3.7/
    :alt: Python versions

.. image:: https://img.shields.io/pypi/v/bases.svg
    :target: https://pypi.python.org/pypi/bases/
    :alt: PyPI version

.. image:: https://img.shields.io/pypi/status/bases.svg
    :target: https://pypi.python.org/pypi/bases/
    :alt: PyPI status

.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
    :target: https://github.com/python/mypy
    :alt: Checked with Mypy
    
.. image:: https://readthedocs.org/projects/bases/badge/?version=latest
    :target: https://bases.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. image:: https://github.com/hashberg-io/bases/actions/workflows/python-pytest.yml/badge.svg
    :target: https://github.com/hashberg-io/bases/actions/workflows/python-pytest.yml
    :alt: Python package status

.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square
    :target: https://github.com/RichardLitt/standard-readme
    :alt: 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 <https://github.com/multiformats/multibase>`_ (except for proquints).


.. contents::


Install
-------

You can install the latest release from `PyPI <https://pypi.org/project/bases/>`_ as follows:

.. code-block:: console

    $ 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. <LICENSE>`_



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hashberg-io/bases",
    "name": "bases",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "hashberg",
    "author_email": "sg495@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/49/30/bdd7f0d7c4c34dac9b932c4fa5de0459af00f53a06e042445f80da3bcc7e/bases-0.2.1.tar.gz",
    "platform": "",
    "description": "bases: A Python library for Base-N encodings\n============================================\n\n.. image:: https://img.shields.io/badge/python-3.7+-green.svg\n    :target: https://docs.python.org/3.7/\n    :alt: Python versions\n\n.. image:: https://img.shields.io/pypi/v/bases.svg\n    :target: https://pypi.python.org/pypi/bases/\n    :alt: PyPI version\n\n.. image:: https://img.shields.io/pypi/status/bases.svg\n    :target: https://pypi.python.org/pypi/bases/\n    :alt: PyPI status\n\n.. image:: http://www.mypy-lang.org/static/mypy_badge.svg\n    :target: https://github.com/python/mypy\n    :alt: Checked with Mypy\n    \n.. image:: https://readthedocs.org/projects/bases/badge/?version=latest\n    :target: https://bases.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://github.com/hashberg-io/bases/actions/workflows/python-pytest.yml/badge.svg\n    :target: https://github.com/hashberg-io/bases/actions/workflows/python-pytest.yml\n    :alt: Python package status\n\n.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square\n    :target: https://github.com/RichardLitt/standard-readme\n    :alt: standard-readme compliant\n\n\nBases provides a customisable, parametric implementation of several common styles of Base-N encoding, covering all cases appearing in the `multibase specification <https://github.com/multiformats/multibase>`_ (except for proquints).\n\n\n.. contents::\n\n\nInstall\n-------\n\nYou can install the latest release from `PyPI <https://pypi.org/project/bases/>`_ as follows:\n\n.. code-block:: console\n\n    $ pip install --upgrade bases\n\n\nUsage\n-----\n\nWe suggest you import bases as follows:\n\n>>> import bases\n\n\nBelow are some basic usage examples, to get you started: for detailed documentation, see https://bases.readthedocs.io/\n\n\nBase encoding objects\n^^^^^^^^^^^^^^^^^^^^^\n\n>>> from bases import base32\n>>> base32\nFixcharBaseEncoding(\n    StringAlphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',\n                   case_sensitive=False),\n    pad_char='=', padding='include')\n\n\nEncoding\n^^^^^^^^\n\n>>> b = bytes([70, 98, 190, 187, 66, 224, 178])\n>>> base32.encode(b)\n'IZRL5O2C4CZA===='\n\n\nDecoding\n^^^^^^^^\n\n>>> s = 'IZRL5O2C4CZA===='\n>>> base32.decode(s)\nb'Fb\\xbe\\xbbB\\xe0\\xb2'\n>>> list(base32.decode(s))\n[70, 98, 190, 187, 66, 224, 178]\n\n\nCase/padding variations\n^^^^^^^^^^^^^^^^^^^^^^^\n\n>>> b = bytes([70, 98, 190, 187, 66, 224, 178])\n>>> base32.encode(b)\n'IZRL5O2C4CZA===='\n>>> base32lower = base32.lower()\n>>> base32lower\nFixcharBaseEncoding(\n    StringAlphabet('abcdefghijklmnopqrstuvwxyz234567',\n                   case_sensitive=False),\n    pad_char='=', padding='include')\n>>> base32lower.encode(b)\n'izrl5o2c4cza===='\n>>> base32nopad = base32.nopad()\n>>> base32nopad.encode(b)\n'IZRL5O2C4CZA'\n\n\nCase sensitivity variations\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n>>> s = 'IZRL5O2C4CZA===='\n>>> base32lower.decode(s)\nb'Fb\\xbe\\xbbB\\xe0\\xb2'\n>>> base32lower_casesensitive = base32lower.with_case_sensitivity(True)\n>>> base32lower_casesensitive.decode(s)\nbases.encoding.errors.NonAlphabeticCharError: Invalid character 'I'\nencountered for alphabet StringAlphabet('abcdefghijklmnopqrstuvwxyz234567').\n\n\nCustom base encodings\n^^^^^^^^^^^^^^^^^^^^^\n\n>>> base4 = bases.make(\"0123\", kind=\"zeropad-enc\", block_nchars=4)\n>>> base4\nZeropadBaseEncoding(StringAlphabet('0123'), block_nchars=4)\n\n\n\nAPI\n---\n\nFor the full API documentation, see https://bases.readthedocs.io/\n\n\nContributing\n------------\n\nPlease see `<CONTRIBUTING.md>`_.\n\n\nLicense\n-------\n\n`MIT \u00a9 Hashberg Ltd. <LICENSE>`_\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python library for general Base-N encodings.",
    "version": "0.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/hashberg-io/bases/issues",
        "Homepage": "https://github.com/hashberg-io/bases"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "74d5b0e135bd2fd2f63a71ddf79583e700a5ba140b636d111ec8f84dfba8af11",
                "md5": "3a7f7fb9c676fca5e542bac85cf41123",
                "sha256": "d030b5e349773ad2a067bfaaf3a9794b70d23a1f923033c15c2e0ce869854f6d"
            },
            "downloads": -1,
            "filename": "bases-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a7f7fb9c676fca5e542bac85cf41123",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 35827,
            "upload_time": "2021-12-30T18:32:11",
            "upload_time_iso_8601": "2021-12-30T18:32:11.204772Z",
            "url": "https://files.pythonhosted.org/packages/74/d5/b0e135bd2fd2f63a71ddf79583e700a5ba140b636d111ec8f84dfba8af11/bases-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4930bdd7f0d7c4c34dac9b932c4fa5de0459af00f53a06e042445f80da3bcc7e",
                "md5": "48b5c32f197335911042d9c5f2dd3de4",
                "sha256": "b0999e14725b59bff38974b00e918629e0e29f3d80a40e022c6f0f8d5cdff9d4"
            },
            "downloads": -1,
            "filename": "bases-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "48b5c32f197335911042d9c5f2dd3de4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 55577,
            "upload_time": "2021-12-30T18:32:13",
            "upload_time_iso_8601": "2021-12-30T18:32:13.188620Z",
            "url": "https://files.pythonhosted.org/packages/49/30/bdd7f0d7c4c34dac9b932c4fa5de0459af00f53a06e042445f80da3bcc7e/bases-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-30 18:32:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hashberg-io",
    "github_project": "bases",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "bases"
}
        
Elapsed time: 0.06689s