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.

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 pep8 pylint
$ python setup.py nosetests --with-coverage
  (...)
$ pep8 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.5.0 (2016-12-19)

  • Add default isort config.

  • Activate tests on Python 3.3, 3.5, 3.6-dev, 3.7-dev, PyPy2 and PyPy3.

  • Remove popularity badge: PyPI download counters are broken and no longer displayed.

  • Move coverage config to setup.cfg.

  • Add test and develop dependencies.

  • Only show latest changes in the long description of the package instead of the full changelog.

  • Add default PyLint config.

  • Add default pycodestyle config.

  • Enforce pycodestyle checks in Travis CI jobs.

  • Test production of packages in Travis CI jobs.

  • Always check for package metadata in Travis CI jobs.

  • Make wheels generated under Python 2 environnment available for Python 3 too.

  • Add link to full changelog in package’s long description.

Full changelog.

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.5.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distributions

scaleway_sdk-1.5.0-py2.py3-none-any.whl (20.6 kB view details)

Uploaded Python 2 Python 3

scaleway_sdk-1.5.0-py2.7.egg (16.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for scaleway-sdk-1.5.0.tar.gz
Algorithm Hash digest
SHA256 4612c45817fab83d41ce06099e68811dd2a38db55e12dca8d22c1ca6b38345aa
MD5 e336ffa94b0499b3bb0a298740dce181
BLAKE2b-256 0fe760825bb567b7b53f7ed577e4efc9fc490b6965062103ebce8ec270aeac26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scaleway_sdk-1.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 42731044631d627000741d09f40c9bd05aabe2e92d2af5a8e5223a99ec956a3e
MD5 0e4cb5390cefcc0f12e45631c8beeb9b
BLAKE2b-256 055df0882bc14c0e8837bfb9cf52e4bd47f9050dcb4e6f2066590c13a45ea8e8

See more details on using hashes here.

File details

Details for the file scaleway_sdk-1.5.0-py2.7.egg.

File metadata

File hashes

Hashes for scaleway_sdk-1.5.0-py2.7.egg
Algorithm Hash digest
SHA256 b7a4f00388793201ff2481aa1ed7d94af354fc091f69f4ad5107f86f128f7836
MD5 0e68203f7bfc102ea3a9e09dca515bc1
BLAKE2b-256 3cced89226bd39ea08d652c6496b463a6d7212f9f9bc1203aedadf7023d803d6

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