pyshn
=====

My python swiss army knife.

Installing
----------

Install and update using `pip`_:

.. code-block:: text

    $ pip install -U pyshn

.. _pip: https://pip.pypa.io/en/stable/quickstart/

Usage
-----

.. code-block:: python

    from pyshn.cpf import cpf

    print(cpf(1))
    # raises pyshn.cpf.CpfError: invalid number '1'

    print(cpf(191))
    # 000.000.001-91

    print(cpf("191"))
    # raises pyshn.cpf.CpfError: invalid format '191'.

    print(cpf("00000000191"))
    # 000.000.001-91

    print(cpf("000000001/91"))
    # 000.000.001-91

    print(cpf("000.000.001-91"))
    # 000.000.001-91

    print(format(cpf(191)))
    # 000.000.001-91

    print(format(cpf(191), 'n'))
    # 00000000191

    print(format(cpf(191), 'N'))
    # 000000001/91

    print(format(cpf(191), 'chewbacca'))
    # ValueError: Invalid format specifier

    print(int(cpf(191)))
    # 191

    print(cpf(1, generate=True))
    # 000.000.001-91

    print(cpf("1", generate=True))
    # pyshn.cpf.CpfError: invalid format '1'.

    print(cpf("000000001", generate=True))
    # 000.000.001-91

    print(cpf("000.000.001", generate=True))
    # 000.000.001-91

    print(cpf(1, validate=False))
    # 000.000.000-01

    print(bool(cpf(1, validate=False)))
    # False

    print(bool(cpf(191, validate=False)))
    # True

    from random import random
    print(cpf(int(random()*999_999_999), generate=True))
    # 238.671.110-22

Links
-----

-   PyPI Releases: https://pypi.org/project/pyshn/
-   Source Code: https://github.com/shneiderfku/pyshn/
-   Issue Tracker: https://github.com/shneiderfku/pyshn/issues/  