Todos Novo

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Entrar


Todos Novo Entrar

All gists matching topic schema

Mais recente criado
Menos recente criado
Mais recente atualizado
Menos recente atualizado

timmy / 使用 pydantic 進行數據驗證與模型定義

0 curtidas
0 bifurcações
3 arquivos
Última atividade 9 months ago
pydantic 提供基於 Python 類別的數據驗證與解析功能,適用於 API 請求驗證、資料模型定義、設定管理 等場景。
data-modeling data-validation pydantic python schema
1 from pydantic import BaseModel, Field, ValidationError
2
3 class User(BaseModel):
4 name: str = Field(..., title="使用者名稱", min_length=2)
5 age: int = Field(..., gt=0, le=150, description="年齡必須介於 1 到 150 之間")
6 email: str
7
8 # 測試資料
9 try:
10 user = User(name="Tim", age=30, email="tim@example.com")
Próximo Anterior

Desenvolvido por Opengist ⋅ Load: 12ms⋅

Português
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文