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我是否需要构造一个带有*非final*但不可变字段的不可变类?   java如何使用jaxb读取属性?   java为什么不打印空值以外的任何内容?   java Struts2如何在不使用struts的情况下重定向到操作。xml?   java方法参数未在其实现中使用   在Java中更改终端内部的变量   Spring中的java依赖项注入失败   java如何使用getAttribute Selenium防止获取重复的HREF   优先级队列的java顺序不符合预期   java如何使用Spring TaskExecutor在应用程序的所有请求中使用单个任务池   java Firebase RecyclerView不会从数据库中检索项目并将其显示在屏幕上。屏幕是空的   java将YUV_420_888转换为字节数组   spring停止使用Java缓存文件   java在执行maven clean安装时,我在eclipse智能家居中遇到了这种错误   stream Java=下载缓冲区未满?冲洗/缓冲是如何工作的?   查询SQL server时重置java JDBC连接   java如何避免在两个函数中使用相同的逻辑。   转换java。lang.Boolean到Scala Boolean