Skip to main content

Sora Watermark Remover - Allows you to remove the watermark from Sora videos.Try Now

CurateClick

utype.io favicon

utype - 基于 Python 类型注解的数据解析与类型安全保障库

utype 是一个基于 Python 类型注解的数据类型声明与解析库,能够在运行时根据声明对类与函数的参数进行解析转化,保障项目类型安全。支持函数参数类型声明解析、简洁约束和类型声明、多种逻辑条件组合类型等。

Check out utype - 基于 Python 类型注解的数据解析与类型安全保障库 on CurateClick

• Copy the embed code to showcase this product on your website

• Share on X to spread the word about this amazing tool

  • 项目地址:https://github.com/utilmeta/utype * 官网:https://utype.io/ * 中文文档:https://utype.io/zh/- 类别:Python- 项目标题:utype - 基于 Python 类型注解的数据解析与类型安全保障库- 项目描述:utype 是一个基于 Python 类型注解的数据类型声明与解析库,能够在运行时根据你的声明对类与函数的参数进行解析转化,保障项目的类型安全- 亮点:相比于pydantic 等库,支持了对函数参数类型声明的解析(包括生成器与异步函数),支持简洁的约束和类型声明,支持多种逻辑条件组合类型,支持丰富的解析选项与偏好配置- 示例代码:pythonimport utype@utype.parsedef login( username: str = utype.Param(regex='[0-9a-zA-Z]{3,20}'), password: str = utype.Param(min_length=6)): # 你可以直接开始编写逻辑了 return username, passwordprint(login('alice', 123456))('alice', '123456')try: login('@invalid', 123456)except utype.exc.ParseError as e: print(e) """ parse item: ['username'] failed: Constraint: <regex>: '[0-9a-zA-Z]{3,20}' violated """``````pythonfrom utype import Schema, Field, excfrom datetime import datetimeclass UserSchema(Schema): username: str = Field(regex='[0-9a-zA-Z]{3,20}') signup_time: datetime# 1. 正常输入data = {'username': 'bob', 'signup_time': '2022-10-11 10:11:12'}print(UserSchema(**data))#> UserSchema(username='bob', signup_time=datetime.datetime(2022, 10, 11, 10, 11, 12))# 2. 异常输入try: UserSchema(username='@invalid', signup_time='2022-10-11 10:11:12')except exc.ParseError as e: print(e) """ parse item: ['username'] failed: Constraint: <regex>: '[0-9a-zA-Z]{3,20}' violated """- 后续更新计划: * 支持生成 json-schema 格式的输入输出模板文档 * 完善解析错误的处理机制,包括错误处理钩子函数等 * 支持环境变量和配置文件的解析和管理 * 支持命令行参数的声明与解析 * 支持 Python 泛型,类型变量等更多类型注解语法 * 开发 Pycharm / VS Code 插件,支持对约束,逻辑类型和嵌套类型的 IDE 检测与提示

Latest Weekly Picks

Impromptu Speech Topics & Timer

Seedance 2.0: Multimodal AI video creator. Precisely direct characters and cameras to create production-ready, multi-shot cinematic stories in one click.

valrequest.net favicon
Weekly Pick

Turn Feelings Into Words

ValRequest

One‑stop AI video creation suite for image‑to‑video and more.

banana-ai.org favicon
Weekly Pick

Nano Banana AI is an AI photo tool for image generation and editing, enabling fast text-prompt edits, style transformations, and photorealistic results.

Nano Banana AI

Try Different Hairstyles Instantly

seedance2.ai favicon
Weekly Pick

Seedance 2 Delivers High Fidelity Motion and Audio Sync

Seedance 2
nanobananaimg.com favicon
Weekly Pick

Nano Banana AI Image Generator for Professional Image Creation with Nano Banana Pro Models

Nano Banana