Skip to content

Field Types Overview

Fastpy CLI supports a rich set of field types with built-in validation rules.

Field Definition Syntax

name:type:rules
  • name - Field name (snake_case)
  • type - Field type (see below)
  • rules - Comma-separated validation rules

Examples

bash
# Basic
-f title:string:required

# With max length
-f title:string:required,max:200

# Multiple rules
-f email:email:required,unique,index

# Foreign key
-f user_id:integer:foreign:users.id

Available Types

Basic Types

TypePython TypeSQL Type
stringstrVARCHAR(255)
textstrTEXT
integerintINTEGER
floatfloatFLOAT
booleanboolBOOLEAN
datetimedatetimeDATETIME

Advanced Types

TypePython TypeDescription
emailstrEmail with validation
urlstrURL with validation
uuidUUIDUUID primary/foreign key
decimalDecimalPrecise decimal
moneyDecimalCurrency amount
percentDecimalPercentage (0-100)
datedateDate only
timetimeTime only
phonestrPhone number
slugstrURL-friendly slug
ipstrIP address
jsondictJSON/JSONB
colorstrHex color code
filestrFile path
imagestrImage path

Validation Rules

RuleDescriptionExample
requiredField cannot be nulltitle:string:required
nullableField can be nullbio:text:nullable
uniqueUnique constraintemail:email:unique
indexCreate indexslug:slug:index
max:NMaximum length/valuetitle:string:max:200
min:NMinimum length/valueage:integer:min:0
default:VDefault valueactive:boolean:default:true
foreign:T.CForeign keyuser_id:integer:foreign:users.id

Quick Reference

bash
# User profile fields
-f username:string:required,unique,max:50,index
-f email:email:required,unique
-f password:string:required,min:8
-f avatar:image:nullable
-f bio:text:nullable,max:500
-f is_active:boolean:default:true
-f role:string:default:user

# Blog post fields
-f title:string:required,max:200
-f slug:slug:required,unique,index
-f body:text:required
-f excerpt:string:nullable,max:300
-f featured_image:image:nullable
-f published:boolean:default:false
-f published_at:datetime:nullable
-f author_id:integer:required,foreign:users.id

# E-commerce fields
-f name:string:required,max:200
-f sku:string:required,unique,max:50
-f price:money:required,min:0
-f sale_price:money:nullable
-f quantity:integer:default:0,min:0
-f weight:decimal:nullable
-f category_id:integer:foreign:categories.id

Next Steps

Released under the MIT License.