Skip to content

Attribute

Attribute

Bases: TemplateModel

A class that represents an attribute in a template model.

Attributes:

Name Type Description
name

str: The name of the model. Name should be snake_case. From TemplateModel

type DataType

DataType: The type of the attribute.

default Any | None

Any|None: The default value of the attribute. Defaults to None.

unique bool

bool: Whether or not the attribute is unique. Defaults to False.

optional bool

bool: Whether or not the attribute is optional. Defaults to False.

validation list[Callable[[Any], Any]]

list[Callable[[Any],Any]]: Not implemented.

Source code in warp_fastapi\attributes.py
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
class Attribute(TemplateModel):
    """
    A class that represents an attribute in a template model.

    Attributes:
        name: str: The name of the model. Name should be snake_case. From TemplateModel
        type: DataType: The type of the attribute.
        default: Any|None: The default value of the attribute. Defaults to None.
        unique: bool: Whether or not the attribute is unique. Defaults to False.
        optional: bool: Whether or not the attribute is optional. Defaults to False.
        validation: list[Callable[[Any],Any]]: Not implemented.
    """

    type: DataType
    default: Any | None = None
    unique: bool = False
    optional: bool = False
    validation: list[Callable[[Any], Any]] = []

    # TODO: add validation for type and default value
    def __init__(
        self,
        name: str,
        type: DataType,
        default: Any = None,
        unique: bool = False,
        optional: bool = False,
        validation_rules: list[Callable[[Any], Any]] = [],
    ) -> None:
        """
        Initializes the attribute with the given arguments.

        Args:
            name: str: The name of the attribute.
            type: DataType: The type of the attribute.
            default: Any: The default value of the attribute. Defaults to None.
            unique: bool: Whether or not the attribute is unique. Defaults to False.
            optional: bool: Whether or not the attribute is optional. Defaults to False.
            validation_rules: list[Callable[[Any],Any]]: Not implemented.
        """
        super().__init__(
            name=name,
            type=type,
            default=default,
            unique=unique,
            optional=optional,
            validation_rules=validation_rules,
        )

__init__(name, type, default=None, unique=False, optional=False, validation_rules=[])

Initializes the attribute with the given arguments.

Parameters:

Name Type Description Default
name str

str: The name of the attribute.

required
type DataType

DataType: The type of the attribute.

required
default Any

Any: The default value of the attribute. Defaults to None.

None
unique bool

bool: Whether or not the attribute is unique. Defaults to False.

False
optional bool

bool: Whether or not the attribute is optional. Defaults to False.

False
validation_rules list[Callable[[Any], Any]]

list[Callable[[Any],Any]]: Not implemented.

[]
Source code in warp_fastapi\attributes.py
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
def __init__(
    self,
    name: str,
    type: DataType,
    default: Any = None,
    unique: bool = False,
    optional: bool = False,
    validation_rules: list[Callable[[Any], Any]] = [],
) -> None:
    """
    Initializes the attribute with the given arguments.

    Args:
        name: str: The name of the attribute.
        type: DataType: The type of the attribute.
        default: Any: The default value of the attribute. Defaults to None.
        unique: bool: Whether or not the attribute is unique. Defaults to False.
        optional: bool: Whether or not the attribute is optional. Defaults to False.
        validation_rules: list[Callable[[Any],Any]]: Not implemented.
    """
    super().__init__(
        name=name,
        type=type,
        default=default,
        unique=unique,
        optional=optional,
        validation_rules=validation_rules,
    )

BoolAttribute(name, default=None, unique=False, optional=False)

Creates bool type attribute with DataType bool_type

Source code in warp_fastapi\attributes.py
102
103
104
105
@validate_call
def BoolAttribute(name: str, default: bool | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates bool type attribute with DataType bool_type"""
    return Attribute(name, bool_type, default, unique, optional)

DateAttribute(name, default=None, unique=False, optional=False)

Creates date type attribute with DataType date_only_type

Source code in warp_fastapi\attributes.py
108
109
110
111
@validate_call
def DateAttribute(name: str, default: date | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates date type attribute with DataType date_only_type"""
    return Attribute(name, date_only_type, default, unique, optional)

DateTimeAttribute(name, default=None, unique=False, optional=False)

Creates datetime type attribute with DataType date_time_type

Source code in warp_fastapi\attributes.py
114
115
116
117
118
119
@validate_call
def DateTimeAttribute(
    name: str, default: datetime | None = None, unique: bool = False, optional: bool = False
) -> Attribute:
    """Creates datetime type attribute with DataType date_time_type"""
    return Attribute(name, date_time_type, default, unique, optional)

DecimalAttribute(name, default=None, unique=False, optional=False)

Creates Decimal type attribute with DataType decimal_type

Source code in warp_fastapi\attributes.py
94
95
96
97
98
99
@validate_call
def DecimalAttribute(
    name: str, default: Decimal | None = None, unique: bool = False, optional: bool = False
) -> Attribute:
    """Creates Decimal type attribute with DataType decimal_type"""
    return Attribute(name, decimal_type, default, unique, optional)

DescriptionAttribute(default=None, unique=False, optional=False)

Creates string type attribute with DataType string_type. Default attribute name is description.

Source code in warp_fastapi\attributes.py
156
157
158
159
@validate_call
def DescriptionAttribute(default: str | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates string type attribute with DataType string_type. Default attribute name is description."""
    return Attribute('description', string_type, default, unique, optional)

EmailAttribute(name='email', default=None, unique=True, optional=False)

Creates email type attribute with DataType email_type. Default attribute name is email and it is set as unique

Source code in warp_fastapi\attributes.py
136
137
138
139
140
141
@validate_call
def EmailAttribute(
    name: str = 'email', default: EmailStr | None = None, unique: bool = True, optional: bool = False
) -> Attribute:
    """Creates email type attribute with DataType email_type. Default attribute name is email and it is set as unique"""
    return Attribute(name, email_type, default, unique, optional)

FloatAttribute(name, default=None, unique=False, optional=False)

Creates float type attribute with DataType float_type

Source code in warp_fastapi\attributes.py
88
89
90
91
@validate_call
def FloatAttribute(name: str, default: float | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates float type attribute with DataType float_type"""
    return Attribute(name, float_type, default, unique, optional)

IntAttribute(name, default=None, unique=False, optional=False)

Creates int type attribute with DataType int_type

Source code in warp_fastapi\attributes.py
82
83
84
85
@validate_call
def IntAttribute(name: str, default: int | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates int type attribute with DataType int_type"""
    return Attribute(name, int_type, default, unique, optional)

NameAttribute(default=None, unique=False, optional=False)

Creates string type attribute with DataType string_type. Default attribute name is name

Source code in warp_fastapi\attributes.py
144
145
146
147
@validate_call
def NameAttribute(default: str | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates string type attribute with DataType string_type. Default attribute name is name"""
    return Attribute('name', string_type, default, unique, optional)

StringAttribute(name, default=None, unique=False, optional=False)

Creates string type attribute with DataType string_type

Source code in warp_fastapi\attributes.py
76
77
78
79
@validate_call
def StringAttribute(name: str, default: str | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates string type attribute with DataType string_type"""
    return Attribute(name, string_type, default, unique, optional)

TimeAttribute(name, default=None, unique=False, optional=False)

Creates time type attribute with DataType time_type

Source code in warp_fastapi\attributes.py
122
123
124
125
@validate_call
def TimeAttribute(name: str, default: time | None = None, unique: bool = False, optional: bool = False) -> Attribute:
    """Creates time type attribute with DataType time_type"""
    return Attribute(name, time_type, default, unique, optional)

TimeDeltaAttribute(name, default=None, unique=False, optional=False)

Creates timedelata type attribute with DataType timedelta_type

Source code in warp_fastapi\attributes.py
128
129
130
131
132
133
@validate_call
def TimeDeltaAttribute(
    name: str, default: timedelta | None = None, unique: bool = False, optional: bool = False
) -> Attribute:
    """Creates timedelata type attribute with DataType timedelta_type"""
    return Attribute(name, timedelta_type, default, unique, optional)

UsernameAttribute()

Creates string type attribute with DataType string_type. Default attribute name is username. Attribute is always unique and it is not optional without default value.

Source code in warp_fastapi\attributes.py
150
151
152
153
def UsernameAttribute() -> Attribute:
    """Creates string type attribute with DataType string_type. Default attribute name is username.
    Attribute is always unique and it is not optional without default value."""
    return Attribute('username', string_type, default=None, unique=True, optional=False)