Skip to content

UUID, Email & DateTime

PyGo provides built-in validated scalar types for common use cases:

  • UUID: Universally Unique Identifier (v4 by default)
  • Email: RFC 5322-compliant email address
  • DateTime: ISO 8601 datetime with timezone awareness
  • URL: Validated URL string
  • Phone: Validated phone number string
  • Decimal: Decimal type for precise arithmetic

All scalar types are validated at compile time and generate idiomatic Go and Python code.

model User:
id: UUID # Auto-generated v4 UUID
name: String

Go:

type User struct {
ID string `json:"id"`
Name string `json:"name"`
}

Python:

import uuid
class User(BaseModel):
id: uuid.UUID
name: str
CREATE TABLE user (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL
);
model Contact:
email: Email
name: String

Emails are validated at compile time:

# Valid
contact = Contact(email="user@example.com", name="Alice")
# Invalid — compile-time error
# contact = Contact(email="not-an-email", name="Bob")

Format: local-part@domain (RFC 5322 compliant)

Go:

type Contact struct {
Email string `json:"email"`
Name string `json:"name"`
}

Python:

class Contact(BaseModel):
email: str # validated on assignment
name: str
model Event:
title: String
started_at: DateTime
ended_at: DateTime?
model Article:
title: String
created: DateTime = now() # Set on creation
updated: DateTime? # Optional, updated manually

All DateTime fields store timezone-aware datetimes in UTC by default:

event = Event(
title="Launch",
started_at="2024-01-15T09:00:00+05:00" # Timezone-aware
)
# Internally stored as UTC
# event.started_at → 2024-01-15 04:00:00 UTC

Go:

import "time"
type Event struct {
Title string
StartedAt time.Time
EndedAt *time.Time
}

Python:

from datetime import datetime
class Event(BaseModel):
title: str
started_at: datetime
ended_at: Optional[datetime] = None
CREATE TABLE event (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
started_at TIMESTAMP WITH TIME ZONE,
ended_at TIMESTAMP WITH TIME ZONE
);
model Website:
url: URL
name: String

Validated URL string (e.g., https://example.com/path).

model Contact:
phone: Phone
name: String

Validated phone number string (e.g., +1-555-123-4567).

model Product:
name: String
price: Decimal

Precise decimal type for financial calculations.

Go:

type Product struct {
Name string
Price string // Decimal stored as string for precision
}

Python:

from decimal import Decimal
class Product(BaseModel):
name: str
price: Decimal
model Profile:
user_id: UUID
secondary_email: Email? = None
last_login: DateTime? = None
model Group:
name: String
member_ids: Array[UUID]
Type Python Type Go Type DB Type
UUID uuid.UUID string UUID
Email str (validated) string TEXT
DateTime datetime time.Time TIMESTAMP
URL str string TEXT
Phone str string TEXT
Decimal Decimal string TEXT
  • Always use UUID as primary keys — never auto-increment integers
  • Validate emails at the model level, not at the controller layer
  • Store all datetimes in UTC — convert to local time only for display
  • Use Decimal for monetary or precise numerical values
  • Use Email? for optional email fields