Skip to main content

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

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.3.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

trafaret-0.7.3-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file trafaret-0.7.3.tar.gz.

File metadata

  • Download URL: trafaret-0.7.3.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for trafaret-0.7.3.tar.gz
Algorithm Hash digest
SHA256 13b3a33c7f2e05af39d81e6a7238cf6be26a8b0fa4b4c1ac7af5d86608111022
MD5 3402bf92f3450457439289b3efabe8c3
BLAKE2b-256 8749a43540aa962910b138ee29f40d03c632735a920f1804d59c3b34ced6b5de

See more details on using hashes here.

File details

Details for the file trafaret-0.7.3-py3-none-any.whl.

File metadata

File hashes

Hashes for trafaret-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a316e41920b62aee01974aa938d09f7426e1bff840a66ef151f114d4eb85d1a
MD5 7de4e18a01739f22a9d2e87796a46152
BLAKE2b-256 4d5a6b4e6044aaec9e38c8970988409a20293b22d4b663ca69d2fb36bf4ca789

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page