Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

this is a test package for packing python liberaries tutorial.

Project Description
# Python SDK 接入指南 & CHANGELOG

## 接入指南
1. Python version >= 3.0
2. 修改config.py中的app_key和secret配置以及callback_url配置,将开发者中心后台申请的应用沙箱环境的app_key和secret分别填入配置文件,填写callback_url
3. 使用sdk提供的接口进行开发调试
4. 上线前将config.py中__sandbox值设为True以及填入正式环境的key和secret以及callback_url


## 代码示例

### 企业应用

- 第一步 引入sdk和项目配置

mkdir sdk && cd sdk && git clone git@github.com:ahahaber/python-sdk.git

```python
from sdk.library.oauth.oauth_client import OAuthClient
from sdk.library.apis.shop_service import ShopService
from sdk.library.protocol.rpc_client import RpcClient
from sdk.config import Config
```

- 第二步 实例化一个oauth2.0客户端授权模式的授权对象

```python
oauth_client = OAuthClient(Config.get_app_key(), Config.get_secret(), Config.get_callback_url())
```

- 第三步 获取生成授权url

```python
auth_url = oauth_client.get_auth_url(state, scope)
```

- 第四步 在授权url中同意授权后,会跳转到CALLBACK_URL的页面,在通过链接上的参数,获取授权码code


- 第五️步 通过code获取token对象,此步获取到的token对象可在有效期内一直使用,不用每次调用前都去获取一次,建议应用授权一次后存放到全局缓存中

```python
token = oauth_client.get_token_by_code(code)
```

- 第六步 实例化远程调用的client对象

```python
rpc_client = RpcClient(token, Config.get_app_key(), Config.get_secret(), Config.get_api_server_url())
```

- 第七步 实例化一个服务对象

```python
shop_service = ShopService(rpc_client)
```

- 第八步 调用服务方法,获取资源数据

```python
shop = shop_service.get_shop(123456)
```

- 第九步 如果token过期,通过refresh_token换取新的token
```python
refresh_token = token["refresh_token"]
token = oauth_client.get_token_by_refresh_token(refresh_token, scope)
```

### 个人应用


- 第一步 引入sdk和项目配置

mkdir sdk && cd sdk && git clone git@github.com:ahahaber/python-sdk.git

```python
from sdk.library.oauth.oauth_client import OAuthClient
from sdk.library.apis.shop_service import ShopService
from sdk.library.protocol.rpc_client import RpcClient
from sdk.config import Config
```

- 第二步 实例化一个oauth2.0客户端授权模式的授权对象

```python
oauth_client = OAuthClient(Config.get_app_key(), Config.get_secret(), Config.get_callback_url())
```

- 第三️步 获取token对象,此步获取到的token对象可在有效期内一直使用,不用每次调用前都去获取一次,建议应用授权一次后存放到全局缓存中

```python
token = oauth_client.get_token_in_client_credentials()
```

- 第四步 实例化远程调用的client对象

```python
rpc_client = RpcClient(token, Config.get_app_key(), Config.get_secret(), Config.get_api_server_url())
```

- 第五步 实例化一个服务对象

```python
shop_service = ShopService(rpc_client)
```

- 第六步 调用服务方法,获取资源数据

```python
shop = shop_service.get_shop(123456)
```


## CHANGELOG:

### [v1.1.2]

Release Date : 2017-02-09

- [BugFix] 修复了token获取的问题

### [v1.1.1]

Release Date : 2017-01-24

- [Feature] 重新支持个人应用授权,在oauth_client中添加get_token_in_client_credentials方法

### [v1.1.0]

Release Date : 2017-01-24

- [Feature] 更新了授权模式为企业应用授权,个人应用授权的方法不在支持,对应的工具类由client_credentials更换为oauth_client

### [v1.0.4]

Release Date : 2017-01-19

- [Feature] 新增UserService

### [v1.0.3]

Release Date : 2017-01-04

- [Improvement] token传入的时候由字符串改为对象,并添加了本地校验

### [v1.0.2]

Release Date : 2016-12-21

- [Improvement] updateItem添加了参数categoryId


### [v1.0.1]

Release Date : 2016-12-02

- [Improvement] 升级使用python3


### [v1.0.0]

Release Date : 2016-11-19

- [Feature] sdk完整实现
- [Feature] 增加接口调用代码示例 demo/main.py
Release History

Release History

This version
History Node

1.0.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
zhupengfei.eleme-1.0.0.tar.gz (3.5 kB) Copy SHA256 Checksum SHA256 Source Mar 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting