magento xml-rpc api的python包装器。
python-magento的Python项目详细描述
这是magento的xml-rpc api的一个简单的python接口。美国石油学会 发现并使所有magento的api方法对您可用。
用法
frommagentoimportMagentoAPImagento=MagentoAPI("magentohost.com",80,"test_api_user","test_api_key")magento.help()# Prints out all resources discovered and available.# cart: create, info, license, order, totals# cart_coupon: add, remove# ... (a bunch of other resources)# sales_order: addComment, cancel, hold, info, list, unholdmagento.sales_order.help()# 'sales_order' is a resource.# sales_order: Order API# - addComment: Add comment to order# - cancel: Cancel order# - hold: Hold order# - info: Retrieve order information# - list: Retrieve list of orders by filters# - unhold: Unhold order# Let's list sales and add their subtotals!orders=magento.sales_order.list()subtotals=[order["subtotal"]fororderinorders]revenue=sum(subtotals)# Additionally, you can get API metadata from these calls:json_description_of_resources=magento.resources()json_description_of_possible_global_exceptions=magento.global_faults()json_description_of_possible_resource_exceptions=magento.resource_faults("sales_order")
api发现并使magento的所有api方法可用于 你。学习如何使用api的最好方法是使用它 在python shell中并返回到Magento API documentation 关于使用特定方法的文档。
快速ipython外壳
magento api是巨大的,需要努力摸索。如果你需要使用 在某种生产能力下,你会想跳进一个空壳里 经常和输入混在一起,盯着输出。
magento-ipython-shell将把您放入具有 变量绑定到已准备好使用的magentoapi对象。
贝壳需要伊普顿,那是蜜蜂的膝盖。安装并获取 它先起作用。或者,启动一个python shell并实例化 你需要的东西。这只是一个稍微好一点的开始 到处乱跑。
以下是启动方法:
> magento-ipython-shell localhost.com 8888 api_user api_key -- magento-ipython-shell ----------------- Connecting to 'http://localhost.com:8888/magento/api/xmlrpc' Using API user/key api_user/api_key Connected! The 'magento' variable is bound to a usable MagentoAPI instance. -- magento-ipython-shell ----------------- Python 2.7.2 (default, Jun 16 2012, 12:38:40) Type "copyright", "credits" or "license" for more information. IPython 0.13.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]:
现在您可以处理magento实例了。
In [1] magento Out[1]: <magento.MagentoAPI at 0x107d3c310> In [2]: magento.help() # Lists all the resources available and their methods. Resources: cart: create, info, license, order, totals cart_coupon: add, remove ... (many more) In [3]: magento.cart.help() # Describes the methods available under a resource. cart: Shopping Cart - create: Create shopping cart - info: Retrieve information about shopping cart - license: Get terms and conditions - order: Create an order from shopping cart - totals: Get total prices for shopping cart In [4]: len(magento.sales_order.list()) # Play around with output. Out[4]: 2
安装
python magento在pypi上:
- pip install python-magento
- easy_install python-magento
…或者获取此代码并运行setup.py install