loaders

enopy provides a set of core loaders for important types that are available out of the box (in addition to the possiblity to pass your own custom loaders as functions/lambdas on all accessors).

The loaders are exposed through the API as drop in replacements to the standard accessors:

  • Field
    • value() => [loader_name]()
  • Fieldset
    • entry() => [loader_name]()
  • List
    • items() => [loader_name]_items()
  • Section
    • field() => [loader_name]()
    • list() => [loader_name]_list()

So for instance, instead of calling ...

>>> document.field('done', required=True)
'yes'
>>> document.list('visitor_counts', required=True)
[ '476', '213', '330', ... ]

... you can just replace field or augment list with the loader name ...

>>> document.boolean('done', required=True)
True
>>> document.integer_list('visitor_counts', required=True)
[ 476, 213, 330, ... ]

... and the method signature stays exactly the same as for the original accessor (except you can't provide a loader as an argument anymore).

Here's another full example:

>>> from enopy import parse

>>> doc = parse("""
...   publish: yes
...   location: 36.987094, -25.091719
...   contact: contact@faulty
... """)

>>> doc.boolean('publish')
True
  
>>> doc.lat_lng('location')
{ 'lat':  36.987094, 'lng': -25.091719 }
  
>>> doc.email('contact')
ValidationError: 'contact' must contain a valid email address, for instance 'jane.doe@eno-lang.org'.

Note that some loaders only perform validation and return their input unaltered as string (e.g. color, email), while others both validate and transform the value into a new type (e.g. float, boolean) or even object (e.g. lat_lng).

Subpages

boolean
color
comma_separated
date
datetime
float
integer
json
lat_lng
number
string
url