没有项目描述
marsha的Python项目详细描述
玛莎
基于输入模块的python 3序列化和验证库。
状态
实验性
不要将此代码放在服务器上。你可以,但你可能不应该。
文档
https://dekar01.gitlab.io/marsha
功能
严格性
当使用python的内置类型进行模式注释时,数据必须是 指定类型或加载操作的实例将失败,并出现异常。 默认情况下,意外和丢失的数据将出错。
清晰度
验证错误反映数据的结构,提供对值的洞察 这导致了错误,并提供有意义的信息以帮助解决问题。
速度
默认功能是快速和精简。性能下降 开发人员明确选择了复杂的功能。
灵活性
自定义数据类型是通过定义格式化程序类创建的,然后转换为 与内置打字模块兼容的类型。
表现力
python的内置类型泛型可以用来声明 知道如何使用简洁明了的语法自动处理多种类型。
安装
pip install marsha
用法
需要从用户输入创建数据库模型实例并以序列化形式公开它们吗?< /P> 创建与模型分离的模式是声明"视图"和
允许定义多个架构来控制数据在不同上下文中的公开方式。 只需要验证一些数据并将其转换为正确的类型?< /P> 可以通过以下方式自动将任何模型的类型批注注册为架构
添加frommy_app.database_modelsimportArtist,AlbumimportmarshafromtypingimportList@marsha.schema(Artist)classArtistSchema:name:str@marsha.schema(Album)classAlbumSchema:title:strartists:List[Artist]# dict -> Albumalbum=marsha.load(album_data,Album)# Do stuffalbum.save()# Album -> dictresponse_data=marsha.dump(album)
schema
decorator。importmarshafromtypingimportList@marsha.schema()classArtist(dict):name:str@marsha.schema()classAlbum(dict):title:strartists:List[Artist]# dict -> dictalbum=marsha.load(album_data,Album)# Do stufffirst_artist=album['artists'][0]
开发
依赖关系
# python >= 3.6
pip install -r dev-requirements.txt
测试
# Quick testing.
flake8
pytest
# Ensure all statements and branches are covered with tests.
pytest --cov=marsha --cov-branch --cov-report html --cov-report term
# Ensure documentations changes render correctly.
make html
推荐PyPI第三方库