Tutti Nuovi

user:thomas utente che ha creato il gist

title:mygist titolo del gist

filename:myfile.txt nome di file nel gist

extension:yml estensione del file nel gist

language:go linguaggio del file nel gist

topic:homelab gists with given topic

Entra


Tutti Nuovi Entra

All gists matching topic schema

Più recente creazione
Meno recente creazione
Più recente aggiornamento
Meno recente aggiornamento

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

0 mi piace
0 forks
3 files
Ultima volta attivo 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")
Più nuovi Più vecchi

Creato da Opengist ⋅ Load: 16ms⋅

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