API

class pyrecord.Record(*values_by_field_order, **values_by_field_name)

Base class for record types.

Changed in version 1.0rc2: Class attribute __module__ is set to the name of the module creating the record type, making it possible to pickle records.

Raises pyrecord.exceptions.RecordInstanceError:
 If too few or too many arguments are passed, or unknown field names are referenced.

Field values can be passed by position, name or both. When passed by position, the order of the fields in the current record type is used.

copy()

Return a shallow copy of the current record.

Return type:Record
static create_type(type_name, *field_names, **default_values_by_field_name)

Return a new record type of name type_name.

Parameters:type_name (str) – The name of the new record type.
Raises pyrecord.exceptions.RecordTypeError:
 If type_name or some field_names are not valid Python identifiers, some field_names are duplicated or default_values_by_field_name refers to an unknown field name.
Return type:A sub-class of Record

All the field names must be passed by position. Any default values for them must be passed by name.

classmethod extend_type(subtype_name, *field_names, **default_values_by_field_name)

Return a new sub-type of name type_name for the current record type.

Parameters:subtype_name (str) – The name of the new record sub-type.
Raises pyrecord.exceptions.RecordTypeError:
 If subtype_name or some field_names are not valid Python identifiers, some field_names are duplicated, some field_names clash with fields in a super-type or default_values_by_field_name refers to an unknown field name.
Return type:A sub-class of the current class

All the field names must be passed by position. Any default values for them must be passed by name.

field_names = ()

Ordered collection of field names in the current record type.

This is populated by create_type() and extend_type().

get_field_values()

Return the current field values by name.

Return type:dict
classmethod init_from_generalization(generalized_record, **field_values)

Specialize generalized_record to an instance of the current record type.

Raises pyrecord.exceptions.RecordInstanceError:
 If generalized_record is not a generalization of the current type or field_values is incomplete.

Values for any fields specific to the specialization must be passed by name.

classmethod init_from_specialization(specialized_record)

Generalize specialized_record to an instance of the current record type.

Raises pyrecord.exceptions.RecordInstanceError:
 If specialized_record is not a specialization of the current type.
exception pyrecord.exceptions.RecordException

Abstract base class for all the exceptions raised by PyRecord.

exception pyrecord.exceptions.RecordInstanceError

Exception for errors at the record instance-level.

exception pyrecord.exceptions.RecordTypeError

Exception for errors at the record type-level.