数据序列化和验证库

lollipop的Python项目详细描述


License: MITBuild StatusDocumentation StatusPyPI

数据序列化和验证库

功能

  • 具有强大类型组合器
  • 的灵活模式定义API
  • 数据验证
  • 序列化/反序列化
  • 就地反序列化

示例

fromlollipop.typesimportObject,String,Datefromlollipop.validatorsimportLengthfromcollectionsimportnamedtuplefromdatetimeimportdatePerson=namedtuple('Person',['name'])Book=namedtuple('Book',['title','publish_date','author'])PersonType=Object({'name':String(validate=Length(min=1)),},constructor=Person)BookType=Object({'title':String(),'publish_date':Date(),'author':PersonType,},constructor=Book)harryPotter1=Book(title='Harry Potter and the Philosopher\'s Stone',publish_date=date(1997,6,26),author=Person(name='J. K. Rowling'))# DumpingBookType.dump(harryPotter1)# => {'title': 'Harry Potter and the Philosopher\'s Stone',#     'publish_date': '1997-06-26',#     'author': {'name': 'J. K. Rowling'}}# LoadingBookType.load({'title':'Harry Potter and the Philosopher\'s Stone','publish_date':'1997-06-26','author':{'name':'J. K. Rowling'}})# => Book(title='Harry Potter and the Philosopher\'s Stone',#         publish_date=date(1997, 06, 26),#         author=User(name='J. K. Rowling'))# Partial inplace loadingBookType.load_into(harryPotter1,{'publish_date':'1997-06-27'})# => Book(title='Harry Potter and the Philosopher\'s Stone',#         publish_date=date(1997, 06, 27),#         author=User(name='J. K. Rowling'))# Loading list of objectsList(BookType).load([{'title':'Harry Potter and the Philosopher\'s Stone','publish_date':'1997-06-26','author':{'name':'J. K. Rowling'}},{'title':'Harry Potter and the Chamber of Secrets','publish_date':'1998-07-02','author':{'name':'J. K. Rowling'}},])# => [Book(...), Book(...)]# ValidationBookType.validate({'title':'Harry Potter and the Philosopher\'s Stone','author':{'name':''},})# => {'author': {'name': 'Length should be at least 1'},#     'publish_date': 'Value is required'}

安装

$ pip install lollipop

文件

文档可在http://lollipop.readthedocs.io/获得。

要求

  • python>;=2.6或<;=3.6

许可证

麻省理工学院许可有关详细信息,请参见捆绑的LICENSE文件

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javascript问题:通过URL用网站数据填充Textview   java TabLayout Android,如何用几个标签填充整个屏幕宽度,并用大量标签滚动?   Eclipse Java运行的文件不再存在于我的工作区中   安装两个Java版本时,使用Java的windows链接不起作用   java将多个图形添加到单个JPanel   java Kafka ConsumerFactory,带有两个Desiarizer   使用反射更改java类超类   当一致性测试失败时,java有没有办法让堆栈跟踪显示在控制台中   java映射到基元类型的HashMap的快速替代方案是什么?   java关闭一个jframe所有剩余的打开jframe都将关闭。   java为什么不推荐“使用getString()获取设备标识符”?   java值比较和值赋值之间有什么性能差异吗?   Java实体数组到JavaScript数组   java使用流将一个列表转换为另一个列表   在JTree中保存对象,但更改显示的名称(java swing)?   java“Hello world”Android应用程序,文件尽可能少,没有IDE,只有文本编辑器   java在方法之间传递值   java如何为项目数组创建ParseQuery?