Biryani Design

Features

  • Procedural, not declarative: Every converter is a function.
  • Bad input isn’t exceptional: Converters don’t raise exceptions they return a couple (value, error).
  • No value is not a value: When a converter is called with None it does nothing since it has no value to convert and returns (None, None).
  • No magic: No decorator, no metaclass, no class, ..., nothing but simple functions.
  • Once again: No class. No attribute to define, no method to override, no instance to create.
  • No symmetry: A conversion from A to B is not handled by the same converter as a conversion from B to A.
  • Lean and mean: Each converter does only one thing. To do more, combine converters.
  • Easy combination: Every converter can be combined with any other converters.
  • Homogeneity: Every converter has the same signature (input: the value and an optional context, output: a couple (converted value, error)).
  • Extensibility: Creating a converter means just writing a new function with the same signature.

Consequences

  • Using a converter is just calling a function.
  • Creating a new converter is easy.
  • But combining existing converters is even easier.
  • Mixing converters with Python code is as easy.
  • Converters enhancements are incremental.
  • Biryani can be used to validate and/or convert anything to anything (HTML forms, CSV files, XML files, etc).

Table Of Contents

Previous topic

Biryani - A Python conversion and validation toolbox

Next topic

Tutorial 1: Validating a web form

This Page