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

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

推荐PyPI第三方库


热门话题
java如何按专辑中曲目的数量过滤这些歌曲   JavaSWT:如何从动作创建普通按钮   java如何使用具有此特定公式的未排序数组实现二叉搜索树?   java PDFBox 2.0.4:提取图像时内存使用率高   java无法实例化类型集   JavaSpring服务周期性任务   java如何在用户打开活动时发出网络请求,但前提是自上次请求已过24小时?   c#如何从Hibernate/NHibernate中的值对象引用实体?   在命令行上运行java时,显示sql server错误消息“java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver”   java数据提供者和断言   java模运算符未给出正确的结果   如何将Eclipse java项目部署到jar文件中   java动态规划问题“以输入价格购买玩家后,总评分必须最高”   java我必须为数组的每个元素制作getter setter吗?   未调用java JUnit RunListener   java如何计算加入多播socket的客户端?