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

Uploaded Source

Built Distribution

trafaret-0.7.6-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trafaret-0.7.6.tar.gz
Algorithm Hash digest
SHA256 648c49f9f4c315309fd77f25bf87d90b5b2c5a1c1bed4a5c0200f33722c8841a
MD5 48cd2b644c2f76da32911fea36d944de
BLAKE2b-256 96d430923fdb786abf27799112f68576191f566b945b006ce2b02390eb15beec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trafaret-0.7.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e14df33ee18ac162733bbf26629bf8e39111791d73006945fa37d125e747462d
MD5 0daaca9252f6d9508476609d6c57b300
BLAKE2b-256 d34ba9bcb5b04165de77a8599bae4b1b1041f0325b68f4690c9fd6172e95c715

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