使用api并对其负责。
eater的Python项目详细描述
使用api并对其负责。
并不是每个api提供者都有像Stripe那么好的api,而且通常 文档是不正确的或(可以说是更好的)不存在。
并不是每个api提供者都能管理自己的发布周期,比如通知客户, 符合语义版本号等
如果你读到这篇文章的话,你很有可能是在试图像 这个
你想确定的是,当你给他们寄东西的时候,他们给了你权利 东西回来了。也就是说,它包含数据的写入形状和正确的数据 类型,如果你真的很吝啬,它会根据定义的规则进行验证
在schematics的帮助下,这个python库将允许您 就这样。
安装
pip install eater
用法
不是说这件事发生在任何人身上,而是说你是 处理不一定信任的api。也许API在 flux,因为它是alpha/beta版本,或者可能没有版本控制,所以会进行更改 不通知用户无论如何,你要确定它说的是什么 是的,绝对是的
使用eater,首先定义要使用的api,部分使用schematics 模型。
importeaterfromschematicsimportModel,IntegerType,StringType,BooleanType,ListType,ModelTypeclassBook(Model):title=StringType(required=True,min_length=3)classRequest(Model):""" Represents, as a Python object, the JSON data required by the API. """in_print=BooleanType()classResponse(Model):""" Represents, as a Python object, the JSON response returned by the API. """books=ListType(ModelType(Book))classBooksAPI(eater.HTTPEater):url='https://example.com/books/'request_cls=Requestresponse_cls=Response
然后您可以使用api;
api=BooksAPI()response=api(in_print=True)forbookinresponse.books:print(book.title)