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.5.tar.gz
(17.7 kB
view details)
Built Distribution
trafaret-0.7.5-py3-none-any.whl
(19.1 kB
view details)
File details
Details for the file trafaret-0.7.5.tar.gz
.
File metadata
- Download URL: trafaret-0.7.5.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd6097fef322b2afe3cc7cd54619bd8c081e8e1f9dd4cb6fbcdd03cc6388d000 |
|
MD5 | b27cb7c0df4c92fbad9f1052bd13195b |
|
BLAKE2b-256 | 38e4abf5ffaac106058c4eedda3269765fb97574cdd7ce7bc17e58de7a89513f |
File details
Details for the file trafaret-0.7.5-py3-none-any.whl
.
File metadata
- Download URL: trafaret-0.7.5-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a78774fb0e18949ec8fe0c16d9f9d0c2fb5cae8f4bdc413700565ee450d04d4 |
|
MD5 | bd6b79f83581c373918ba9e76d285eb6 |
|
BLAKE2b-256 | 917ed21b38ee916c0730d95621e5424c0f62f2626d3c76bb04dacfa0661a4c97 |