是否有OData Python库?

53 投票
6 回答
25363 浏览
提问于 2025-04-16 06:41

我在想有没有适合Python的OData库,可以用来生成和使用OData?

不同的编程语言都有相关的实现,具体可以查看这个链接:http://www.odata.org/libraries/

不过到目前为止我还没找到适合Python的库。顺便说一下,我不是指IronPython,我是说那种可以直接在Python中使用的库。

6 个回答

7

我之前开始了一个自己的OData 4.0消费项目。这个项目是用纯Python写的,基于requests库。因为我只实现了工作中需要的功能,所以这个项目比较简单。你可以在我的github上看看。

它的工作方式大致是这样的:

from odata import ODataService
url = 'http://services.odata.org/V4/Northwind/Northwind.svc/'
Service = ODataService(url, reflect_entities=True)
Product = Service.entities['Product']

query = Service.query(Product)
query = query.filter(Product.ProductName.startswith('Queso'))
query = query.order_by(Product.UnitPrice.desc())
for product in query:
    print(product.ProductName)
7

我最近在我维护的一个名为Pyslet的电子学习项目的Python包中添加了一些OData模块。这个项目托管在Github上,链接在这里:https://github.com/swl10/pyslet

我写了一篇介绍性的博客文章,展示了OData消费者的功能,链接在这里:http://swl10.blogspot.co.uk/2014/02/a-dictionary-like-python-interface-for.html

16

我是这个库的作者,地址在 http://code.google.com/p/odata-py/。这个库还在初期阶段,但已经提供了一些最基本的功能,比如创建、读取和更新。如果你发现了bug或者想要贡献什么,随时给我留言哦;)

撰写回答