All New

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

Login


All New Login

All gists matching topic pydantic

Recently created
Least recently created
Recently updated
Least recently updated

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

0 likes
0 forks
3 files
Last active 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")

timmy / 使用 Streamlit 與 Pydantic 建立使用者資訊展示

0 likes
0 forks
1 files
Last active 10 months ago
這段程式碼使用 pydantic 來定義使用者模型,並且透過 Streamlit 在網頁上顯示使用者資訊,同時 pretty_errors 提供美觀的錯誤訊息格式。
data-validation pretty-errors pydantic python streamlit user-model web-dashboard
1 from datetime import date
2
3 import pretty_errors
4 import streamlit as st
5 from pydantic import BaseModel, Field
6
7
8 class User(BaseModel):
9 id: int
10 name: str
Newer Older

Powered by Opengist ⋅ Load: 31ms⋅

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