Skip to main content

Python SDK to query Scaleway APIs.

Project description

Python SDK to query Scaleway’s APIs.

Stable release: Last release Python versions Software license Requirements freshness

Development: Unit-tests status Coverage Status Code Quality

Installation

The package is available on pip. To install it in a virtualenv:

$ virtualenv my_virtualenv
$ source my_virtualenv/bin/activate
$ pip install scaleway-sdk

General principle

If you’re looking to send a GET HTTP request against our APIs, like:

GET <api_url>/foo/bar

you only need to call the following pythonic code:

>>> from scaleway.apis import DummyAPI
>>> DummyAPI().query().foo.bar.get()

The magic here lies in scaleway.apis.*API instances, which all have a query method returning a slumber.API object. The latter handling all the excruciating details of the requests.

Documentation

Even if this SDK is designed to be developer-friendly and aim for self-service discovery, it is still recommended to read the official API documentation.

And because most of the provided helpers takes the form of pre-configured Slumber objects, a good read of Slumber documention is encouraged as well.

The list of available resources per API can be found [on the Scaleway API repository](https://github.com/scaleway/api.scaleway.com/blob/master/README.md#apis)

Examples

  • List your organizations:

>>> from scaleway.apis import AccountAPI
>>> api = AccountAPI(auth_token='')  # Set your token here!
>>> print api.query().organizations.get()
{u'organizations': [...]}
  • List your organizations, but get a flask.Response object instead of a 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': [...]}
  • List your servers:

>>> 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': [...]}
  • Get details of a server:

>>> 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': {...}}
  • Check if your token has the permission servers:read for the service compute for the organization 9a096d36-6bf9-470f-91df-2398aa7361f7:

>>> 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

Development

Assuming you are in a virtualenv:

$ pip install -e .
$ python -c 'from scaleway.apis import AccountAPI'
  # it works!

Test

To submit a patch, you’ll need to test your code against python2.7 and python3.4. To run tests:

$ pip install nose coverage pycodestyle pylint
$ python setup.py nosetests --with-coverage
  (...)
$ pycodestyle scaleway
  (...)
$ pylint scaleway
  (...)
  • Coverage score should never be lower than before your patch.

  • PEP8 should never return an error.

  • Pylint score should never be lower than before your patch.

Alternatively, to run nosetests on both Python2.7 and Python3.4, you can run tox.

Alternative libraries / clients

We maintain a list of the current library/client implementations on the api.scaleway.com repository.

License

This software is licensed under a BSD 2-Clause License.

Changes for v1.8.0 (2019-01-28)

  • Target tests on Python 3.7 and 3.8-dev.

  • Remove Python 3.3 support.

  • In AccountAPI.get_quotas(), request more than the default 50 lines, quick fix of CP-1660

Full changelog.

Project details


Download files

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

Source Distribution

scaleway-sdk-1.8.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distributions

scaleway_sdk-1.8.0-py3.7.egg (34.0 kB view details)

Uploaded Source

scaleway_sdk-1.8.0-py2.py3-none-any.whl (18.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file scaleway-sdk-1.8.0.tar.gz.

File metadata

  • Download URL: scaleway-sdk-1.8.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for scaleway-sdk-1.8.0.tar.gz
Algorithm Hash digest
SHA256 cac3a9b80747939d27e4b39e13bda353c0a1df2b5a421178feeed28ff7ca55a2
MD5 8dd64cfd8f9739d70ffb9efed47222c8
BLAKE2b-256 97cb8ae31986071522ad350b4826e2da1d2484754c932c19554d71833107d715

See more details on using hashes here.

File details

Details for the file scaleway_sdk-1.8.0-py3.7.egg.

File metadata

  • Download URL: scaleway_sdk-1.8.0-py3.7.egg
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for scaleway_sdk-1.8.0-py3.7.egg
Algorithm Hash digest
SHA256 ab6186ae47ab718808f652fe7851d0fab1f3ae2718f165cdb1d62732cf296411
MD5 8dda3688bd1c9f2e3ab22e3c88c29b73
BLAKE2b-256 15cb0a5c0e84da2040d9ac92eeb75cd78c12cd315ecea8f2fe3747f99c1fc27f

See more details on using hashes here.

File details

Details for the file scaleway_sdk-1.8.0-py2.py3-none-any.whl.

File metadata

  • Download URL: scaleway_sdk-1.8.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for scaleway_sdk-1.8.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 162dc4bf14c9f7268a032e55abb66924608eb68bcd39176c90dea429f617e39e
MD5 2382df81e46e49933e7f797b1a403743
BLAKE2b-256 4643f113e4e0d29961557e330cba62651671e789f66ca2cd655d1b017ad7eef9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page