跳转到主要内容

用于查询Scaleway API的Python SDK。

项目描述

Python SDK 用于查询 ScalewayAPIs.

稳定版本: 最新发布 Python 版本 软件许可

开发: 单元测试状态 覆盖率状态 代码质量

安装

该软件包可在 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-2398aa7361f7compute 服务 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 (19.2 kB 查看哈希值)

上传时间 源代码

构建分发

scaleway_sdk-1.15.0-py2.py3-none-any.whl (18.3 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面