Working With Views

Views are mutable structures that store data based on Record instances. The field names are the same, except instead of getting type instances for all the attributes, you get fields that can store and delete data.

In addition to essentially being a Mutable Record, a View makes it easy to drop in place of existing modeling systems, like maybe, Schematics…

Views are created with Type instances, and they can be instantiated with data.

>>> view = SomeRecord().to_view({'foo': 'bar'})
>>> view.foo
'bar'

API

class typerighter.views.Field(name)[source]

A descriptor used to join a mutable View instance, that stores data, with the immutable Type instance, that only defines methods for operating on data.

class typerighter.views.View(record, data=None, native=True, primitive=False)[source]

A View combines a Record with a dictionary to provide an object modeled after the record that can store data in a familiar object oriented manner.

to_native(**convert_args)[source]

Uses the record’s to_native to convert view data.

to_primitive(**convert_args)[source]

Uses the record’s to_primitive to convert view data.

validate()[source]

Uses the record’s validate function with view data.

typerighter.views.to_view(record, data=None, **view_config)[source]

Takes both a record and some data and produces View instance.

Parameters
  • record (Type) – The type that defines the view’s shape

  • data (dict) – Any initial data for the view’s fields