用于查询Scaleway API的Python SDK。
项目描述
Python SDK 用于查询 Scaleway 的 APIs.
安装
该软件包可在 pip 上找到。要在虚拟环境中安装它
$ virtualenv my_virtualenv
$ source my_virtualenv/bin/activate
$ pip install scaleway-sdk
一般原则
如果您想对我们 API 发送 GET HTTP 请求,例如
GET <api_url>/foo/bar
您只需要调用以下 Pythonic 代码
>>> from scaleway.apis import DummyAPI
>>> DummyAPI().query().foo.bar.get()
这里的魔法在于 scaleway.apis.*API 实例,它们都具有一个返回 slumber.API 对象的 query 方法。后者处理请求的所有繁琐细节。
文档
尽管此 SDK 是为开发者友好而设计的,并旨在实现自助服务发现,但仍建议阅读官方 API 文档。
并且因为大多数提供的辅助函数都采用预配置的 Slumber 对象的形式,因此也鼓励阅读 Slumber 文档。
每个 API 可用的资源列表可以在 [Scaleway API 存储库中找到](https://github.com/scaleway/api.scaleway.com/blob/master/README.md#apis)
示例
列出您的组织
>>> from scaleway.apis import AccountAPI
>>> api = AccountAPI(auth_token='') # Set your token here!
>>> print api.query().organizations.get()
{u'organizations': [...]}
列出您的组织,但获取一个 flask.Response 对象而不是 dict
>>> from scaleway.apis import AccountAPI
>>> api = AccountAPI(auth_token='') # Set your token here!
>>> resp = api.query(serialize=False).organizations.get()
>>> print type(resp)
<Response [200]>
>>> print resp.headers
{...} # Response HTTP headers.
>>> print resp.links
{...} # Parsed "Link" HTTP header, for pagination.
>>> print resp.json()
{u'organizations': [...]}
列出您的服务器
>>> from scaleway.apis import ComputeAPI
>>> api = ComputeAPI(auth_token='') # Set your token here!
>>> print api.query().servers.get()
{u'servers': [...]}
# Or choose your region, as in apis/api_compute.py
>>> api = ComputeAPI(region='ams1', auth_token='') # Set your token here!
>>> print api.query().servers.get()
{u'servers': [...]}
获取服务器的详细信息
>>> from scaleway.apis import ComputeAPI
>>> api = ComputeAPI(auth_token='') # Set your token here!
>>> server_id = '' # Set a server ID here!
>>> print api.query().servers(server_id).get()
{u'server': {...}}
检查您的令牌是否具有对组织 9a096d36-6bf9-470f-91df-2398aa7361f7 的 compute 服务 servers:read 权限
>>> from scaleway.apis import AccountAPI
>>> api = AccountAPI(auth_token='') # Set your token here!
>>> print api.has_perm(service='compute', name='servers:read',
... resource='9a096d36-6bf9-470f-91df-2398aa7361f7')
False
开发
假设您正在 virtualenv 中
$ pip install -e .
$ python -c 'from scaleway.apis import AccountAPI'
# it works!
测试
要提交补丁,您需要测试您的代码对python2.7和python3.4的兼容性。要运行测试
$ pip install nose coverage pycodestyle pylint
$ python setup.py nosetests --with-coverage
(...)
$ pycodestyle scaleway
(...)
$ pylint scaleway
(...)
覆盖率得分不应低于您的补丁之前。
PEP8不应返回错误。
Pylint得分不应低于您的补丁之前。
或者,要同时在Python2.7和Python3.4上运行 nosetests,您可以运行 tox。
替代库/客户端
我们在 api.scaleway.com 仓库 上维护当前库/客户端实现列表。
许可
本软件根据BSD 2-Clause 许可证授权。
1.15.0版本变更(2023-05-12)
添加nl-ams-3 AZ
项目详情
scaleway-sdk-1.15.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 8e3762b24c7dfbbf46ff7c4c9f57de3c17791df254f818608e29363b5ecd4fb7 |
|
MD5 | 1c83fd233c8aadd018ba919a7312914a |
|
BLAKE2b-256 | 8bd72e5dd282a9d295db66b8a5b00c1072ec14291d63eef44c70c8aa0ace404a |
scaleway_sdk-1.15.0-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bcaf446b00a6cb300c4e07062b601a5385fda4ef3c33d522c778ea9a32032ef1 |
|
MD5 | 97f08fbade267013371d43b69aec49ab |
|
BLAKE2b-256 | 957f9cef9b35641bd124072b556d5e8d0a89795ad70105f1f281210118fd3380 |