2018-06-12

Sanic-validation 0.3.0 was just released.A big new feature is support for data normalization. You can have cleaned and normalized data provided directly to your handler method. Renaming of fields, assigning default values and converting types could be done as part of the validation step. This is especially useful for working with query arguments, as they are provided as strings by default.

How to use it?

Let’s say we want to write a service that returns the first count words of Lorem Ipsum. Let’s also assume that we have a list lorem_ipsum_words containing the text split into single words.Our endpoint could look like this:

Because of the coerce rule, count will be parsed with int before validation begins. If conversion fails, an appropriate validation error will be returned. Enabling the clean flag signals that we want cleaned arguments to be passed to our handler function as valid_args. This dictionary will contain count as a number, so we don’t have to manually convert it.

2018-05-27

I’ve recently discovered sanic - a fast, async web server framework.I couldn’t find a good validation library for it, so I wrote my own.Under the hood it uses cerberus to validate data against the supplied schema.Generated error messages provide full path to the offending parameter, and the constraint that was broken.

2018-05-27

2017-08-11

The academic year is officially over.This means I can share a project I’ve been working on for the Programming Languages and Paradigms course.It’s an original programming language and its interpreter, written in Haskell.

The name Cinnabar references a toxic, but also beautiful mineral.The language draws inspiration from JavaScript and Python.