Validation and parsing library
Project description
Trafaret
========
-----
|pypi_downloads| |pypi_version| |pypi_license|
-----
Read The Docs hosted documentation <http://trafaret.readthedocs.org/en/latest/>
or look to the docs/api/intro.rst for start.
Trafaret is rigid and powerful lib to work with foreign data, configs etc.
It provides simple way to check anything, and convert it accordingly to your needs.
For simple example what can be done:
.. code-block:: python
import datetime
import trafaret as t
date = t.Dict(year=t.Int, month=t.Int, day=t.Int) >> (lambda d: datetime.datetime(**d))
assert date.check({'year': 2012, 'month': 1, 'day': 12}) == datetime.datetime(2012, 1, 12)
Work with regex:
.. code-block:: python
>>> c = t.String(regex=r'^name=(\w+)$') >> (lambda m: m.groups()[0])
>>> c.check('name=Jeff')
'Jeff'
Rename dict keys:
.. code-block:: python
>>> c = t.Dict(t.Key('uNJ') >> 'user_name': t.String})
>>> c.check({'uNJ': 'Adam'})
{'user_name': 'Adam'}
``Arrow`` date checking:
.. code-block:: python
import arrow
def check_datetime(str):
try:
return arrow.get(str).naive
except arrow.parser.ParserError:
return t.DataError('value is not in proper date/time format')
Yes, you can write trafarets that simple.
.. |pypi_downloads| image:: https://img.shields.io/pypi/dm/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
.. |pypi_version| image:: https://img.shields.io/pypi/v/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
.. |pypi_license| image:: https://img.shields.io/pypi/l/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
========
-----
|pypi_downloads| |pypi_version| |pypi_license|
-----
Read The Docs hosted documentation <http://trafaret.readthedocs.org/en/latest/>
or look to the docs/api/intro.rst for start.
Trafaret is rigid and powerful lib to work with foreign data, configs etc.
It provides simple way to check anything, and convert it accordingly to your needs.
For simple example what can be done:
.. code-block:: python
import datetime
import trafaret as t
date = t.Dict(year=t.Int, month=t.Int, day=t.Int) >> (lambda d: datetime.datetime(**d))
assert date.check({'year': 2012, 'month': 1, 'day': 12}) == datetime.datetime(2012, 1, 12)
Work with regex:
.. code-block:: python
>>> c = t.String(regex=r'^name=(\w+)$') >> (lambda m: m.groups()[0])
>>> c.check('name=Jeff')
'Jeff'
Rename dict keys:
.. code-block:: python
>>> c = t.Dict(t.Key('uNJ') >> 'user_name': t.String})
>>> c.check({'uNJ': 'Adam'})
{'user_name': 'Adam'}
``Arrow`` date checking:
.. code-block:: python
import arrow
def check_datetime(str):
try:
return arrow.get(str).naive
except arrow.parser.ParserError:
return t.DataError('value is not in proper date/time format')
Yes, you can write trafarets that simple.
.. |pypi_downloads| image:: https://img.shields.io/pypi/dm/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
.. |pypi_version| image:: https://img.shields.io/pypi/v/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
.. |pypi_license| image:: https://img.shields.io/pypi/l/trafaret.svg?style=flat-square
:target: https://pypi-hypernode.com/pypi/trafaret
:alt: Downloads
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
trafaret-0.7.2.tar.gz
(17.5 kB
view details)
Built Distribution
trafaret-0.7.2-py3-none-any.whl
(19.0 kB
view details)
File details
Details for the file trafaret-0.7.2.tar.gz
.
File metadata
- Download URL: trafaret-0.7.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d37d5134e94fb44f2ad9c67d4e84f974816b4ae3fb1b058748f7c20ebdef9758 |
|
MD5 | 0664981824dc461dbfb1b87a147daf0a |
|
BLAKE2b-256 | 9aed90e7f55775219dbb3c9540e737b9d54bde24bb76e61e298ed711880a509c |
File details
Details for the file trafaret-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: trafaret-0.7.2-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c774ca6f6751f61c3e1f492f3f2d3e8402361a78193259f15c371c785f9c1cc |
|
MD5 | 3c7eb1b1ba0e2c964164d48e6aa1efc6 |
|
BLAKE2b-256 | f4210c16b4b64acd5ab2749c4e71151f910b5062e42d51b21ac89b9b85f1da06 |