bfh.fields¶
Fields that can go on Schemas
Included are the common data types you’ll probably need, and a generic Field class so you can implement your own if you want.
-
class
bfh.fields.
Field
(required=True, default=None)¶ Base class for a field.
You can create custom fields if you inherit this and implement serialize and validate as desired:
- class AngryField(Field):
- def serialize(self, value, **kwargs):
- return “I HATE YOU”
- def validate(self, value):
- return False
-
class
bfh.fields.
ArrayField
(array_type=None, **kwargs)¶ A field that can contain an array of things of type array_type
- class Inner(Schema):
- wow = IntegerField()
- class MySchema(Schema):
- ints = ArrayField(int) inners = ArrayField(Inner)
indicates an object that looks like so:
{“ints”: [1, 2, 3], “inners”: [{“wow”: 4}, {“wow”: 5}]}
-
class
bfh.fields.
BooleanField
(required=True, default=None)¶ A field that should contain a boolean.
-
class
bfh.fields.
DatetimeField
(required=True, default=None)¶ A field that should contain a Python datetime object.
-
class
bfh.fields.
IsoDateString
(strict=False, encoding='utf-8', **kwargs)¶ A string field that validates that it contains an ISO 8601 date string
-
class
bfh.fields.
IntegerField
(required=True, default=None)¶ A field that should contain an integer.
-
class
bfh.fields.
NumberField
(required=True, default=None)¶ A field that should contain a floating-point number.
-
class
bfh.fields.
ObjectField
(required=True, default=None)¶ A field that can contain a schemaless dict or object.
-
class
bfh.fields.
Subschema
(subschema_class, *args, **kwargs)¶ A field that defines a subschema.
Define one schema, then you can use this field to embed it in another:
- class Inner(Schema):
- # some fields
- class MySchema(Schema):
- inner = Subschema(Inner) # more fields
-
class
bfh.fields.
UnicodeField
(strict=False, encoding='utf-8', **kwargs)¶ A field that contains strings.
Expect unicode. If it’s not already unicode, assume it’s utf-8 and transform it to unicode.