Moltin Python开发包

moltin的Python项目详细描述


[网站](http://molt.in

许可证:麻省理工学院

版本:1.0

说明

用于moltin电子商务api的python sdk

安装

$ pip install moltin

用法

使用client_id初始化moltin对象,然后 client_secret,以及可选的特定api版本(例如v1)。

frommoltin.moltinimportMoltinm=Moltin("YOUR_CLIENT_ID","YOUR_CLIENT_SECRET"[,version="v1"])

认证

要进行身份验证,请调用authenticate方法。

access_token=m.authenticate()# This returns an AccessToken object# access_token.token: the token string# access_token.has_expired(): has the token expired## The access token is automatically passed to subsequent requests,# so you shouldn't normally need to use the returned token# except when persisting in a session or db

使用用户名/密码进行身份验证:

access_token,refresh_token=m.authenticate(username="your_username",password="your_password")# refresh_token is a RefreshToken object.# refresh_token.token: the token string# Use this to re-authenticate without needing a user/pass

使用刷新令牌字符串进行身份验证:

access_token=m.authenticate(refresh_token="refresh_token_string")

一旦通过身份验证,访问令牌将自动传递给 请求。如果需要传入以前存储的令牌,请使用:

m.set_access_token("access_token_string")

在提出请求之前

进行api调用

有一种与大多数端点交互的简单方法:

product=m.Product# Creates a product wrapperproduct.list()# lists all productsproduct.create(params)# creates a product, params passed as a dictproduct.find(5)# finds product with id = 5product.find_by(params)# finds a single product by params passed as a dict,# e.g. {"title": "Banana"}product.update(5,params)# updates product with id = 5 with new paramsproduct.remove(5)# removes product with id = 5

sdk还提供了一种向 直接API端点

例如:

product=m.get('products/5')# get product with id = 5new_product=m.post('products',{"sku":"123456789","title":"My first product","slug":"my-first-product","price":9.99,"status":1,"category":2,"stock_level":15,"stock_status":6,"description":"This is my first product on Moltin","requires_shipping":0})# create a new productm.put('products/5',params)# update product with id = 5m.delete('products/5')# delete product with id = 5

有关更多示例,请参阅完整的api文档。

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

推荐PyPI第三方库


热门话题
java Android Action_Edit Intent无法像以前一样调用App Gallery来编辑图片   确保JRE兼容性的java适当程序(32或64位)   java JSONArray。for循环中的add(JSONObject)正在替换for循环中的旧值,数组由循环中的最后一个值组成   java需要帮助创建一个返回数组的方法,该数组的元素是另一个数组的平方   使用SmbFile w/groovy XmlSluper()创建xml。解析()Java   检查大小后的java ArrayIndexOutOfBoundsException   乘法表中的第k个最小元素   java 401 on请求,其中指定了'permitAll()'   java如何附加ORC文件   java hibernate类模型   java IDEA没有看到由自定义注释处理器生成的方法   Servlet中未声明java SerialVersionId   java linkedlist到达列表末尾时   java如何正确对齐EditText光标?   java 6编译器1.6上的eclipse重写方法错误   java如何在基于Jersey的RESTful Web服务中读取post数据   java如何在活动中正确使用接口?   Java的JIT编译器的工作速度有多快?