:snake: Python SDK to query Scaleway APIs.

Overview

Scaleway SDK

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.

Comments
  • 404 Error on retrieving organizations

    404 Error on retrieving organizations

    The first example of the readme api.query().organizations.get() fails with error 404: {"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.", "type": "404"}

    opened by DavHau 7
  • Is this sdk still maintained

    Is this sdk still maintained

    I was wondering if this sdk is still maintained by the scaleway team. It still has support for the non-working account.scaleway.com part of the api and doesn't support the new endpoints (like https://api.scaleway.com/account/v2alpha1/ssh-keys for managing ssh keys) that are supported in the scaleway go sdk. Not entirely related to this specific sdk, but this part of the api doesn't seem to be documented anywhere.

    opened by mpaulon 4
  • Not able to specify region because of the Hyphen

    Not able to specify region because of the Hyphen

    Trying to list the RDB instances but I have difficulties to specify the region. That -Hyphen seems to be the problem, but I am not Python expert enough figure out how to escape is correctly.

    api = API(base_url="https://api.scaleway.com", auth_token="yo")
    api.make_requests_session()
    instances = api.query().rdb.v1.regions.fr-par1.instances.get()
    
    Traceback (most recent call last):
      File "executeOrder.py", line 11, in <module>
        instances = api.query().rdb.v1.regions.fr-par1.instances.get()
    NameError: name 'par1' is not defined
    
    opened by Vad1mo 3
  • WIP: feat: add userdata api to SDK

    WIP: feat: add userdata api to SDK

    Hello! This PR implement the reading of user_data information from the SDK. As this feature need to call the base_url with a privileged port, I had to override the python requests object.

    Regarding the unit tests, I didn't find an elegant way to integrate them except mocking get get_userdata method and compare the result to a string (which is basically comparing two static strings). If you have any piece of advice about it, I would be more than happy to integrate them.

    opened by abarbare 3
  • add user_data parameter in create server API

    add user_data parameter in create server API

    I think it would be great to have ability to send user_data(usually text that is interpreted as bash script) when creating a server via the API, https://github.com/scaleway/api.scaleway.com/blob/master/contents/server.md#create-a-new-server-post

    This way, a scaleway customer can be able to specify things that they would like to run during the server creation.

    This already exists in other cloud platforms, eg:

    The ovh create server api has a parameter called userData that you can specify:: https://api.ovh.com/console/#/cloud/project/%7BserviceName%7D/instance#POST The digitalocean API also takes a parameter called user_data, https://developers.digitalocean.com/documentation/v2/#create-a-new-droplet This is very useful especially when you want to automate creation of servers that are different from each other but are based off the same image.

    opened by komuw 3
  • Unclear case with api_account.perm_matches and None request

    Unclear case with api_account.perm_matches and None request

    Reading the following line:

            self.assertTrue(self.api.perm_matches(None, 'object:*'))
    

    I would assume the opposite, can you clarify this case and maybe update the docstring?

    question 
    opened by moul 2
  • fix: keep support for python 2

    fix: keep support for python 2

    cachetools recently drop py2 support, we would like to keep for some time so simply use the latest py2 compatible cachetools when using py2. Py3 is free to use the latest and greatest.

    opened by CedricCabessa 1
  • refactor: move init.py to apis subpackage

    refactor: move init.py to apis subpackage

    As of today because of the scaleway/__init__.py we cannot share the scaleway namespace with other libraries.

    Based on https://packaging.python.org/guides/packaging-namespace-packages/ we implement the "pkgutil-style namespace packages" method

    opened by jerome-quere 1
  • Add a short (ttl-based) cache to `AccountAPI.get_quotas()`

    Add a short (ttl-based) cache to `AccountAPI.get_quotas()`

    The goal is to optimize usecases like this :

    api = AccountAPI(...)
    api.has_quota(organization=organization, resource='servers', used=10)
    api.has_quota(organization=organization, resource='volumes', used=10)
    api.has_quota(organization=organization, resource='ips', used=10)
    

    => we check several quotas of the same organization in a very short period of time, typically within less than 1sec

    In that usecase, the current AccountAPI does 3 calls to API-account, which is sub-optimal. But we can easily cache "in-ram" the response to get_quotas(), because it's getting all quotas of a given organization, and re-use it for the 2nd and 3rd call.

    NB: currently, each call to api-account to get quotas takes ~60 ms, so each call avoided is a lot :)

    opened by frivoire 1
  • Create server raise Client Error 400?

    Create server raise Client Error 400?

    Using following:

    compute_api = ComputeAPI(auth_token=secret_key, region='pl-waw-1')
    
    compute_api.query().servers.post({'project': org_id, "name": 'test', "commercial_type": "DEV1-M"})
    

    Got:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/draven/.local/lib/python2.7/site-packages/slumber/__init__.py", line 167, in post
        resp = self._request("POST", data=data, files=files, params=kwargs)
      File "scaleway/scaleway/apis/__init__.py", line 87, in _request
        return super(SlumberResource, self)._request(*args, **kwargs)
      File "/home/draven/.local/lib/python2.7/site-packages/slumber/__init__.py", line 101, in _request
        raise exception_class("Client Error %s: %s" % (resp.status_code, url), response=resp, content=resp.content)
    slumber.exceptions.HttpClientError: Client Error 400: https://api-pl-waw.scaleway.com/instance/v1/zones/pl-waw-1/servers/
    

    Since there is no documents about how to use POST / Create so based on other sample such as this I assume the above code is correct.

    But Error 400 ?

    opened by DravenJohnson 2
  • Documentation for other request types than GET missing

    Documentation for other request types than GET missing

    All examples in the readme only demonstrate the usage for GET requests. There is not a single example for other request types like POST. I needed to dig inside the docs of Slumber to find out how to do them. Including at least one example on how to create a new server or similar would save some time for a lot of people i guess.

    opened by DavHau 1
  • Exception text not useful

    Exception text not useful

    When a request returns an error the exception printed to the console is quite useless because it does not contain the message of the response. Just the error code. It would be more convenient if the message of result would be included in the Exception text.

    opened by DavHau 0
Releases(v1.14.0)
Owner
Scaleway
APIs, SDKs and open source projects from Scaleway
Scaleway
Bot per controllare la disponibilità di appuntamenti per la vaccinazione Covid-19 in Veneto

VaxBot9000 Prerequisites Python 3.9 Poetry latest version of geckodriver Firefox Setup poetry install Copy config.sample.toml to config.toml and edit

Augusto Zanellato 5 Jun 13, 2021
NekoRobot-2 - Neko is An Anime themed advance Telegram group management bot.

NekoRobot A modular telegram Python bot running on python3 with an sqlalchemy, mongodb database. ╒═══「 Status 」 Maintained Support Group Included Free

Lovely Boy 19 Nov 12, 2022
vk.com API python wrapper

Python vk.com API wrapper This is a vk.com (the largest Russian social network) python API wrapper. The goal is to support all API methods (current an

Dmitry Voronin 371 Dec 29, 2022
Stop writing scripts to interact with your APIs. Call them as CLIs instead.

Zum Stop writing scripts to interact with your APIs. Call them as CLIs instead. Zum (German word roughly meaning "to the" or "to" depending on the con

Daniel Leal 84 Nov 17, 2022
A surviv.io bot that helps you manage you clan in surviv.io!

Scooter-Surviv.io-Clan-Bot A Surviv.io Discord Bot This is a bot that helps manage your surviv.io clan! Read below for more!!. Features Lets you creat

cosmic|duck 1 Jan 03, 2022
Charged's cogs for Red!

Light-Cogs Charged's cogs for Red! Read below for more information. Features and Cogs TechInfo Lots of commands helping you and your devices! Extended

Charged 2 Jan 07, 2022
a simple floating window for watch cryptocurrency price

floating-monitor with cryptocurrency 浮動視窗虛擬貨幣價格監控 a floating monitor window to show price of cryptocurrency. use binance api to get price 半透明的浮動視窗讓你方便

Lin_Yi_Shen 1 Oct 22, 2021
Cyber Userbot

Cyber Userbot

Irham 0 May 26, 2022
BeeDrive: Open Source Privacy File Transfering System for Teams and Individual Developers

BeeDrive For privacy and convenience purposes, more and more people try to keep data on their own hardwires instead of third-party cloud services such

Xuansheng Wu 8 Oct 31, 2022
Github action for automatically determine the version for next release by using repository tags

This action will automatically determine the version for next release by using repository tags

Igor Gov 7 Oct 25, 2022
Muzan-Discord-Nuker - A simple discord server nuker in python

Muzan-Discord-Nuker This is Just a simple discord server nuker in python. ✨ Feat

Afnan 3 May 14, 2022
A Discord Self bot written in python

WitheredBot A Discord Self bot written in python Requirement Python = 3.9 How to Configure git clone https://github.com/a-a-a-aa/WitheredBot.git cd W

......... 0 Jan 05, 2023
A Telegram Bot To Stream Videos in Telegram Voice Chat.

Video Stream X Bot Telegram bot project for streaming video on telegram video chat, powered by tgcalls and pyrogram Deploy to Heroku 👨‍🔧 The easy wa

Mⷨoͦns͛ᴛⷮeͤrͬ Zeͤrͬoͦ 13 Dec 05, 2022
This is a tutorial on how to make a Discord Bot using the discord.py library

HowToMakeADiscordBot This Github repository is here to help you code a Discord Bot using the discord.py library! 1 - Setup: Download the code inside t

Baz 1 Oct 31, 2021
A cool discord bot, called Fifi

Fifi A cool discord bot, called Fifi This bot is the official server bot of Meme Studios discord server. This github repo is the code we use for the b

Fifi Discord Bot 3 Jun 08, 2021
Ma2tl - macOS forensic timeline generator using the analysis result DBs of mac apt

ma2tl (mac_apt to timeline) This is a DFIR tool for generating a macOS forensic

Minoru Kobayashi 66 Nov 18, 2022
EthSema - Binary translator for Ethereum 2.0

EthSema is a novel EVM-to-eWASM bytecode translator that can not only ensure the fidelity of translation but also fix commonly-seen vulnerabilities in smart contracts.

weimin 8 Mar 01, 2022
Video Stream: an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat

Video Stream is an Advanced Telegram Bot that's allow you to play Video & Music on Telegram Group Video Chat 🧪 Get SESSION_NAME from below: Pyrogram

Jonathan 6 Feb 08, 2022
A play store search telegram bot

Play-Store-Bot A play store search telegram bot Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.c

Fayas Noushad 17 Oct 28, 2022
Gnosis-py includes a set of libraries to work with Ethereum and Gnosis projects

Gnosis-py Gnosis-py includes a set of libraries to work with Ethereum and Gnosis projects: EthereumClient, a wrapper over Web3.py Web3 client includin

Gnosis 93 Dec 23, 2022