Skip to main content

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

Predict video virality before you publish.

Virality Predictor

Powerful Motion Control AI Video Generator

Motion Control AI

PlusGO 是面向中国大陆用户的 ChatGPT Plus 代充值服务平台。使用官方 CDKey,支持支付宝和微信扫码支付,平均 2 分钟完成 Plus 开通,自 2025 年起已为超过 10,000 名用户完成充值。

www.toolcenter.ai favicon
Weekly Pick

Discover the Best AI & Productivity Tools — 1,500+ tools with honest reviews.

ToolCenter
huntereyes.net favicon
Weekly Pick

AI Eye Area Evaluation

Hunter Eyes
www.payforchat.com favicon
Weekly Pick

Subscribe to ChatGPT Plus/Pro in 1 minute — no international credit card needed.

PayForChat
happyhorseai.ai favicon
Weekly Pick

Happy Horse AI Creates Videos with Motion and Storytelling

Happy Horse
promptbuilder.cc favicon
Weekly Pick

Generate, optimize, test, and manage AI prompts in one place. Turn an idea into a ready-to-use prompt in seconds.

Prompt Builder