Skip to main content

CurateClick

CurateClick 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

CurateClick favicon

getfacereport.com

Private face analysis with personalized style guidance and hairstyle previews.

CurateClick favicon

lovableapp.org

Discover beautiful apps built with vibe coding

CurateClick favicon

antiquescanner.org

Identify antiques, vintage items and collectibles from photos, with estimated market value.

CurateClick favicon

imagelayered.com

AI-powered image decomposition tool that transforms flat images into editable layers.

CurateClick favicon

kaigpt.ai

gpt代充:如何快速申请免手续费的充值服务?

CurateClick favicon

magiclayers.net

Magic Layers – Official Website, What It Is & How to Use

CurateClick favicon

lifepathcalculator.app

Life Path Calculator - free deterministic numerology: your number, strengths, challenges, and shareable cards.

CurateClick favicon

freeadhd.com

ADHD Test - a free, no-sign-up adult ADHD self-screening tool with instant results.