API Doc

Main function

Copyright 2013, Gilles Devaux

All rights reserved.

voyeur.get_value(obj, key)[source]

Get a value from different type of objects

Parameters:
  • obj – The object to get a value from
  • key – The key
Returns:

The value you want from the object

voyeur.view(data, definition, **kwargs)[source]

Main entry point to create a view of some data

Parameters:
  • data – The original data
  • definition – The definition for creating the view
  • kwargs – User defined arguments that can be passed to the callables
Returns:

The view of the data

Types

class voyeur.types.DeferredType(field, _callable=None)[source]

A type that can read value from another data field.

You can apply a callable to the value

>>> from voyeur import view
>>> definition = {
>>>     'field': DeferredType('anotherfield', int),
>>> }
>>>
>>> data = {'anotherfield': '2'}
>>> result = view(data, definition)
>>> assert result == {'field':2}
class voyeur.types.Type[source]

So you can use objects as fields. You need to use an instance.

The main difference with another callable is that the whole object
will be passed as the first argument and the key as the second
>>> class MyType(Type):
>>>     def __call__(self, *args, **kwargs):
>>>         return 'domything'
>>>
>>> definition = {
>>>     'field': MyType(),
>>> }