Schema¶
The Table Schema model allows to manipulate a Pydantic model in Python according to the Table Schema specification
Usage¶
from dplib.models import Schema, IntegerField
schema = Schema()
schema.add_field(IntegerField(name='id'))
schema.missingValues = ['-']
print(schema.to_text(format="json"))
Reference¶
dplib.models.Schema
¶
Bases: Model
Table Schema model
Source code in dplib/models/schema/schema.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
fields: List[IField] = []
class-attribute
instance-attribute
¶
List of fields in the table schema
fieldsMatch: Optional[IFieldsMatch] = 'exact'
class-attribute
instance-attribute
¶
The way Table Schema fields are mapped onto the data source fields are defined by the fieldsMatch property.
foreignKeys: List[ForeignKey] = []
class-attribute
instance-attribute
¶
A foreign key is a reference where values in a field (or fields) on the table (‘resource’ in data package terminology) described by this Table Schema connect to values a field (or fields) on this or a separate table (resource).
missingValues: IMissingValues = ['']
class-attribute
instance-attribute
¶
A list of field values to consider as null values
primaryKey: List[str] = []
class-attribute
instance-attribute
¶
A primary key is a field or set of fields that uniquely identifies each row in the table.
profile: str = pydantic.Field(default=settings.PROFILE_CURRENT_SCHEMA, alias='$schema')
class-attribute
instance-attribute
¶
A profile URL
uniqueKeys: List[List[str]] = []
class-attribute
instance-attribute
¶
A unique key is a field or a set of fields that are required to have unique logical values in each row in the table.
add_field(field)
¶
Add a field to the schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
IField
|
The field to add |
required |
compat(data)
classmethod
¶
Source code in dplib/models/schema/schema.py
get_field(*, name=None)
¶
Get a field by name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str]
|
The name of the field to get |
None
|
Returns:
Type | Description |
---|---|
Optional[IField]
|
The field with the given name if found |
Source code in dplib/models/schema/schema.py
get_field_names()
¶
Get the names of the fields in the schema
Returns:
Type | Description |
---|---|
List[str]
|
The names of the fields in the schema |
Source code in dplib/models/schema/schema.py
get_field_types()
¶
Get the types of the fields in the schema
Returns:
Type | Description |
---|---|
List[str]
|
The types of the fields in the schema |
Source code in dplib/models/schema/schema.py
dplib.models.IFieldsMatch = Union[Literal['exact'], Literal['equal'], Literal['subset'], Literal['superset'], Literal['partial']]
module-attribute
¶
dplib.models.ForeignKey
¶
Bases: Model
Source code in dplib/models/schema/foreignKey.py
dplib.models.ForeignKeyReference
¶
Bases: Model
Source code in dplib/models/schema/foreignKey.py
dplib.models.BaseField
¶
Bases: Model
Base Field
Source code in dplib/models/field/datatypes/base.py
description: Optional[str] = None
class-attribute
instance-attribute
¶
A description for this field e.g. “The recipient of the funds”
missingValues: IMissingValues = ['']
class-attribute
instance-attribute
¶
A list of field values to consider as null values
name: Optional[str] = None
class-attribute
instance-attribute
¶
The field descriptor MUST contain a name property.
title: Optional[str] = None
class-attribute
instance-attribute
¶
A human readable label or title for the field
type: Optional[Any] = None
class-attribute
instance-attribute
¶
A field type i.e. string, number, etc
compat(data)
classmethod
¶
Source code in dplib/models/field/datatypes/base.py
dplib.models.Field
¶
dplib.models.AnyField
¶
Bases: BaseField
The field contains values of a unspecified or mixed type.
Source code in dplib/models/field/datatypes/any.py
dplib.models.ArrayField
¶
Bases: BaseField
The field contains a valid JSON array.
Source code in dplib/models/field/datatypes/array.py
dplib.models.BooleanField
¶
Bases: BaseField
The field contains boolean (true/false) data.
Source code in dplib/models/field/datatypes/boolean.py
constraints: BaseConstraints[bool] = pydantic.Field(default_factory=BaseConstraints)
class-attribute
instance-attribute
¶
falseValues: List[str] = ['false', 'False', 'FALSE', '0']
class-attribute
instance-attribute
¶
Values to be interpreted as “false” for boolean fields
format: Optional[Literal['default']] = None
class-attribute
instance-attribute
¶
trueValues: List[str] = ['true', 'True', 'TRUE', '1']
class-attribute
instance-attribute
¶
Values to be interpreted as “true” for boolean fields
type: Literal['boolean'] = 'boolean'
class-attribute
instance-attribute
¶
dplib.models.DateField
¶
Bases: BaseField
he field contains a date without a time.
Source code in dplib/models/field/datatypes/date.py
dplib.models.DatetimeField
¶
Bases: BaseField
The field contains a date with a time.
Source code in dplib/models/field/datatypes/datetime.py
dplib.models.DurationField
¶
Bases: BaseField
The field contains a duration of time.
Source code in dplib/models/field/datatypes/duration.py
dplib.models.GeojsonField
¶
Bases: BaseField
The field contains a JSON object according to GeoJSON or TopoJSON spec.
Source code in dplib/models/field/datatypes/geojson.py
dplib.models.GeopointField
¶
Bases: BaseField
The field contains data describing a geographic point.
Source code in dplib/models/field/datatypes/geopoint.py
dplib.models.IntegerField
¶
Bases: BaseField
The field contains integers - that is whole numbers.
Source code in dplib/models/field/datatypes/integer.py
bareNumber: bool = True
class-attribute
instance-attribute
¶
If false leading and trailing non numbers will be removed for integer/number fields
categories: Optional[ICategories] = None
class-attribute
instance-attribute
¶
Property to restrict the field to a finite set of possible values
categoriesOrdered: bool = False
class-attribute
instance-attribute
¶
When categoriesOrdered is true, implementations SHOULD regard the order of appearance of the values in the categories property as their natural order.
constraints: ValueConstraints[int] = pydantic.Field(default_factory=ValueConstraints)
class-attribute
instance-attribute
¶
format: Optional[Literal['default']] = None
class-attribute
instance-attribute
¶
groupChar: Optional[str] = None
class-attribute
instance-attribute
¶
String whose value is used to group digits for integer/number fields
type: Literal['integer'] = 'integer'
class-attribute
instance-attribute
¶
dplib.models.ListField
¶
Bases: BaseField
The field contains data that is an ordered one-level depth collection of primitive values with a fixed item type.
Source code in dplib/models/field/datatypes/list.py
constraints: CollectionConstraints = pydantic.Field(default_factory=CollectionConstraints)
class-attribute
instance-attribute
¶
delimiter: Optional[str] = None
class-attribute
instance-attribute
¶
Specifies the character sequence which separates lexically represented list items.
format: Optional[Literal['default']] = None
class-attribute
instance-attribute
¶
itemType: Optional[IItemType] = None
class-attribute
instance-attribute
¶
Specifies the list item type in terms of existent Table Schema types.
type: Literal['list'] = 'list'
class-attribute
instance-attribute
¶
dplib.models.NumberField
¶
Bases: BaseField
The field contains numbers of any kind including decimals.
Source code in dplib/models/field/datatypes/number.py
bareNumber: bool = True
class-attribute
instance-attribute
¶
If false leading and trailing non numbers will be removed for integer/number fields
constraints: ValueConstraints[float] = pydantic.Field(default_factory=ValueConstraints)
class-attribute
instance-attribute
¶
decimalChar: str = '.'
class-attribute
instance-attribute
¶
String whose value is used to represent a decimal point for number fields
format: Optional[Literal['default']] = None
class-attribute
instance-attribute
¶
groupChar: Optional[str] = None
class-attribute
instance-attribute
¶
String whose value is used to group digits for integer/number fields
type: Literal['number'] = 'number'
class-attribute
instance-attribute
¶
dplib.models.ObjectField
¶
Bases: BaseField
The field contains a valid JSON object.
Source code in dplib/models/field/datatypes/object.py
dplib.models.StringField
¶
Bases: BaseField
The field contains strings, that is, sequences of characters.
Source code in dplib/models/field/datatypes/string.py
categories: Optional[ICategories] = None
class-attribute
instance-attribute
¶
Property to restrict the field to a finite set of possible values
categoriesOrdered: bool = False
class-attribute
instance-attribute
¶
When categoriesOrdered is true, implementations SHOULD regard the order of appearance of the values in the categories property as their natural order.
constraints: StringConstraints = pydantic.Field(default_factory=StringConstraints)
class-attribute
instance-attribute
¶
format: Optional[IStringFormat] = None
class-attribute
instance-attribute
¶
type: Literal['string'] = 'string'
class-attribute
instance-attribute
¶
dplib.models.TimeField
¶
Bases: BaseField
The field contains a time without a date.
Source code in dplib/models/field/datatypes/time.py
dplib.models.YearField
¶
Bases: BaseField
The field contains a calendar year.
Source code in dplib/models/field/datatypes/year.py
dplib.models.YearmonthField
¶
Bases: BaseField
The field contains a specific month of a specific year.
Source code in dplib/models/field/datatypes/yearmonth.py
dplib.models.BaseConstraints
¶
Bases: Model
, Generic[NativeType]
Source code in dplib/models/field/constraints/base.py
dplib.models.CollectionConstraints
¶
Bases: BaseConstraints[str]
Source code in dplib/models/field/constraints/collection.py
dplib.models.JsonConstraints
¶
Bases: CollectionConstraints
Source code in dplib/models/field/constraints/json.py
jsonSchema: Optional[Dict[str, Any]] = None
class-attribute
instance-attribute
¶
dplib.models.StringConstraints
¶
Bases: CollectionConstraints
Source code in dplib/models/field/constraints/string.py
pattern: Optional[str] = None
class-attribute
instance-attribute
¶
dplib.models.ValueConstraints
¶
Bases: BaseConstraints[NativeType]
, Generic[NativeType]