Fields API¶
Field type definitions with validation constraints.
Base Field¶
Field(default=_MISSING, *, primary_key=False, nullable=False, description=None, unique=False, index=False, autoincrement=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_length=None, max_length=None, pattern=None)
¶
Declare field metadata and constraints for Pydantic-style schema definitions.
Use this function with type annotations to define schema fields with constraints, similar to Pydantic's Field() function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Any
|
Default value for the field. Can be provided as first positional argument. |
_MISSING
|
primary_key
|
bool
|
Mark this field as the primary key (for database operations). |
False
|
nullable
|
bool
|
Allow None values for this field. |
False
|
description
|
str
|
Human-readable description of this field. |
None
|
unique
|
bool
|
Enforce uniqueness constraint (for database operations). |
False
|
index
|
bool
|
Create an index on this field (for database operations). |
False
|
autoincrement
|
bool
|
Enable auto-increment for integer fields. |
None
|
gt
|
numeric
|
Value must be greater than this (for int, float, datetime fields). |
None
|
ge
|
numeric
|
Value must be greater than or equal to this. |
None
|
lt
|
numeric
|
Value must be less than this. |
None
|
le
|
numeric
|
Value must be less than or equal to this. |
None
|
multiple_of
|
int
|
Value must be a multiple of this (for integer fields). |
None
|
min_length
|
int
|
Minimum string length (for string fields). |
None
|
max_length
|
int
|
Maximum string length (for string fields). |
None
|
pattern
|
str
|
Regex pattern the string must match (for string fields). |
None
|
Returns:
| Type | Description |
|---|---|
FieldInfo
|
A FieldInfo instance that will be processed by the Schema metaclass. |
Examples:
Basic usage with type annotations:
>>> from flycatcher import Schema, Field
>>> from datetime import datetime
>>> class UserSchema(Schema):
... # Simple fields - just annotations
... name: str
... created_at: datetime
...
... # Fields with defaults
... is_active: bool = True
...
... # Nullable fields
... bio: str | None = None
...
... # Fields with constraints
... age: int = Field(ge=0, le=120)
... email: str = Field(pattern=r'^[^@]+@[^@]+\.[^@]+$')
...
... # Database-specific options
... id: int = Field(primary_key=True, autoincrement=True)
With default value as positional argument:
>>> class ConfigSchema(Schema):
... timeout: int = Field(default=30, ge=1, le=300)
... retries: int = Field(default=3, ge=0)
Source code in src/flycatcher/fields.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
Field Types¶
Integer(*, gt=None, ge=None, lt=None, le=None, multiple_of=None, **kwargs)
¶
Bases: FieldBase
Integer field type with numeric constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gt
|
int
|
Value must be greater than this number. |
None
|
ge
|
int
|
Value must be greater than or equal to this number. |
None
|
lt
|
int
|
Value must be less than this number. |
None
|
le
|
int
|
Value must be less than or equal to this number. |
None
|
multiple_of
|
int
|
Value must be a multiple of this number. |
None
|
**kwargs
|
Additional arguments passed to |
{}
|
Examples:
>>> from flycatcher import Field, Schema
>>> class UserSchema(Schema):
... age: int = Field(ge=0, le=120)
... score: int = Field(gt=0, multiple_of=10)
... id: int = Field(primary_key=True, autoincrement=True)
Source code in src/flycatcher/fields.py
get_polars_constraints()
¶
Generate Polars validation expressions.
Source code in src/flycatcher/fields.py
get_pydantic_field_kwargs()
¶
Return kwargs for Pydantic Field().
Source code in src/flycatcher/fields.py
Float(*, gt=None, ge=None, lt=None, le=None, **kwargs)
¶
Bases: FieldBase
Float field type with numeric constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gt
|
float
|
Value must be greater than this number. |
None
|
ge
|
float
|
Value must be greater than or equal to this number. |
None
|
lt
|
float
|
Value must be less than this number. |
None
|
le
|
float
|
Value must be less than or equal to this number. |
None
|
**kwargs
|
Additional arguments passed to |
{}
|
Examples:
>>> from flycatcher import Field, Schema
>>> class ProductSchema(Schema):
... price: float = Field(gt=0.0)
... discount: float | None = Field(default=None, ge=0.0, le=1.0)
Source code in src/flycatcher/fields.py
get_polars_constraints()
¶
Generate Polars validation expressions.
Source code in src/flycatcher/fields.py
get_pydantic_field_kwargs()
¶
Return kwargs for Pydantic Field().
Source code in src/flycatcher/fields.py
String(*, max_length=None, min_length=None, pattern=None, **kwargs)
¶
Bases: FieldBase
String field type with length and pattern constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_length
|
int
|
Minimum length of the string (inclusive). |
None
|
max_length
|
int
|
Maximum length of the string (inclusive). |
None
|
pattern
|
str
|
Regular expression pattern that the string must match. |
None
|
**kwargs
|
Additional arguments passed to |
{}
|
Examples:
>>> from flycatcher import Field, Schema
>>> class UserSchema(Schema):
... name: str = Field(min_length=1, max_length=100)
... email: str = Field(pattern=r'^[^@]+@[^@]+\.[^@]+$')
... bio: str | None = Field(default=None, max_length=500)
Source code in src/flycatcher/fields.py
get_polars_constraints()
¶
Generate Polars validation expressions.
Source code in src/flycatcher/fields.py
get_pydantic_field_kwargs()
¶
Return kwargs for Pydantic Field().
Source code in src/flycatcher/fields.py
Boolean(*, primary_key=False, nullable=False, default=_MISSING, description=None, unique=False, index=False, autoincrement=None)
¶
Bases: FieldBase
Boolean field type.
Examples:
>>> from flycatcher import Field, Schema
>>> class UserSchema(Schema):
... is_active: bool = True
... is_verified: bool | None = None
Source code in src/flycatcher/fields.py
Datetime(*, gt=None, ge=None, lt=None, le=None, **kwargs)
¶
Bases: FieldBase
Datetime field type for datetime.datetime values.
Examples:
>>> from datetime import datetime
>>> from flycatcher import Schema
>>> class EventSchema(Schema):
... created_at: datetime
... updated_at: datetime | None = None
Source code in src/flycatcher/fields.py
get_polars_constraints()
¶
Generate Polars validation expressions.
Source code in src/flycatcher/fields.py
get_pydantic_field_kwargs()
¶
Return kwargs for Pydantic Field().
Source code in src/flycatcher/fields.py
Date(*, primary_key=False, nullable=False, default=_MISSING, description=None, unique=False, index=False, autoincrement=None)
¶
Bases: FieldBase
Date field type for datetime.date values.
Examples:
>>> from datetime import date
>>> from flycatcher import Schema, Date
>>> class BookingSchema(Schema):
... check_in: date
... check_out: date