Fields

Base Field

class nyoibo.fields.Field

Base Field

This is the base for all field types.

_internal_type

each Field subclass must to override this attribute with the internal type that field represent.

_exceptions

possible exception that could be raised when field tries to cast to _internal_type.

Type:

tuple

Parameters:
  • private (bool) – set if field is private or not. When private=True getter and setters will not be created. False by default.

  • mutable (bool) – set if field is mutable or not. When mutable=False setter will not be created. False by default.

  • default_value (any) – default value to field.

  • choices (Enum) – value to this field must be a Enum key or Enum value.

  • required (bool) – validate if value is not None. False by default.

parse()

Parse and cast to _internal_type

Parameters:

value (any) – value to parse.

Returns:

_internal_type if the casting was successful

Raises:
  • FieldValueError – if the casting failed.

  • RequiredValueError – if a field has required = True and value is None

String Field

class nyoibo.fields.StrField

Field for string values

Parameters:

max_length (int) – maximum lenght for str value

Raises:

AssertionError – if max_length is less than 0.

parse()

Parse and cast to _internal_type

Parameters:

value (any) – value to parse.

Returns:

_internal_type if the casting was successful

Raises:
  • FieldValueError – if the casting failed.

  • RequiredValueError – if a field has required = True and value is None

Integer Field

class nyoibo.fields.IntField

Field for integer values

Parameters:
  • min_value (int) – minimum value

  • max_value (int) – maximum value

Raises:

AssertionError – if min_value or max_value are no integer.

parse()

Parse and cast to integers

Parameters:

value (any) – value to cast

Returns:

(int) casted value

Raises:
  • IntMinValueError – if min_value was set and value is less than min_value.

  • IntMaxValueError – if max_value was set and value is greater than max_value.

Boolean Field

class nyoibo.fields.BoolField

Field for boolean values

Date Field

class nyoibo.fields.DateField

Field for datetime.date values

Values could be datetime.date or isoformat string.

Parameters:
  • formats (iterable) – string formats following `strptime format codes

  • <https – //docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes>`_

Datetime Field

class nyoibo.fields.DatetimeField

Field for datetime.datetime values

Values could be datetime.datetime or isoformat string.

Parameters:
  • formats (iterable) – string formats following `strptime format codes

  • <https – //docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes>`_

Float Field

class nyoibo.fields.FloatField

Field for float values

Decimal Field

class nyoibo.fields.DecimalField

Field for Decimal values

Dict Field

class nyoibo.fields.DictField

Field for dict values

JSON Field

class nyoibo.fields.JSONField

Field for json values.

Tuple Field

class nyoibo.fields.TupleField

Field for tuple values

Parameters:
  • of – Type of items. All items going to be cast to of type.

  • reverse_relationship (bool) – create a reverse relation with of.

Raises:

ValueError – if of is None and reverse_relationship is True

List Field

class nyoibo.fields.ListField

Field for list values

Parameters:

of – Type of items. All items going to be cast to of type. reverse_relationship (bool): create a reverse relation with of.

Raises:

ValueError – if of is None and reverse_relationship is True