Scaleway Python SDK documentation
Installation
This library is made to work with Python 3.8 but should work on the latest versions too.
The SDK is available in two flavors, a synchronous and an asynchronous one.
Install from PyPI:
pip install scaleway
Install from PyPI (async):
pip install scaleway-async
Initialization
You’ll need a pair of access and secret keys to connect to Scaleway API. Please check the documentation on how to retrieve them.
scaleway
APIs must be initialized with a scaleway.Client
.
A minimal setup would look like this:
from scaleway import Client
from scaleway.registry.v1 import RegistryV1API
client = Client(
access_key="SCWXXXXXXXXXXXXXXXXX",
secret_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
default_project_id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
default_region="fr-par",
default_zone="fr-par-1",
)
registry_api = RegistryV1API(client)
- scaleway.Client(access_key: Optional[str] = None, secret_key: Optional[str] = None, api_url: str = 'https://api.scaleway.com', api_allow_insecure: bool = False, user_agent: str = 'scaleway-sdk-python/2.0.0', default_organization_id: Optional[str] = None, default_project_id: Optional[str] = None, default_region: Optional[str] = None, default_zone: Optional[str] = None, default_page_size: Optional[int] = None) None
Profile(access_key: ‘Optional[str]’ = None, secret_key: ‘Optional[str]’ = None, api_url: ‘str’ = ‘https://api.scaleway.com’, api_allow_insecure: ‘bool’ = False, user_agent: ‘str’ = ‘scaleway-sdk-python/2.0.0’, default_organization_id: ‘Optional[str]’ = None, default_project_id: ‘Optional[str]’ = None, default_region: ‘Optional[str]’ = None, default_zone: ‘Optional[str]’ = None, default_page_size: ‘Optional[int]’ = None)
For a simpler setup, you could retrieve the profile from either the configuration file or the environment variables:
from scaleway import Client
client = Client.from_config_file_and_env()
- scaleway.Client.from_config_file_and_env(filepath: Optional[str] = None, profile_name: Optional[str] = 'default') ProfileSelf
Loads profile from a config file and environment variables.
- Environment variables override config file.
If config file is not found, the profile is still loaded from environment variables.
If you want it to throw an error in case of missing or invalid config file, use Profile.from_config_file and Profile.from_env instead.
Pagination
We included some pagination helpers for the methods supporting the feature. Let’s take scaleway.registry.v1.RegistryV1API.list_namespaces()
as an example:
Retrieve the first page:
result = api.list_namespaces(
# page=1,
)
- scaleway.registry.v1.RegistryV1API.list_namespaces(self, *, region: Optional[str] = None, page: Optional[int] = None, page_size: Optional[int] = None, order_by: Optional[ListNamespacesRequestOrderBy] = None, organization_id: Optional[str] = None, project_id: Optional[str] = None, name: Optional[str] = None) ListNamespacesResponse
List namespaces. List all namespaces in a specified region. By default, the namespaces listed are ordered by creation date in ascending order. This can be modified via the order_by field. You can also define additional parameters for your query, such as the instance_id and project_id parameters. :param region: Region to target. If none is passed will use default region from the config. :param page: A positive integer to choose the page to display. :param page_size: A positive integer lower or equal to 100 to select the number of items to display. :param order_by: Criteria to use when ordering namespace listings. Possible values are created_at_asc, created_at_desc, name_asc, name_desc, region, status_asc and status_desc. The default value is created_at_asc. :param organization_id: Filter by Organization ID. :param project_id: Filter by Project ID. :param name: Filter by the namespace name (exact match). :return:
ListNamespacesResponse
Usage:
result = api.list_namespaces()
Retrieve all the pages:
namespaces = api.list_namespaces_all()
- scaleway.registry.v1.RegistryV1API.list_namespaces_all(self, *, region: Optional[str] = None, page: Optional[int] = None, page_size: Optional[int] = None, order_by: Optional[ListNamespacesRequestOrderBy] = None, organization_id: Optional[str] = None, project_id: Optional[str] = None, name: Optional[str] = None) List[Namespace]
List namespaces. List all namespaces in a specified region. By default, the namespaces listed are ordered by creation date in ascending order. This can be modified via the order_by field. You can also define additional parameters for your query, such as the instance_id and project_id parameters. :param region: Region to target. If none is passed will use default region from the config. :param page: A positive integer to choose the page to display. :param page_size: A positive integer lower or equal to 100 to select the number of items to display. :param order_by: Criteria to use when ordering namespace listings. Possible values are created_at_asc, created_at_desc, name_asc, name_desc, region, status_asc and status_desc. The default value is created_at_asc. :param organization_id: Filter by Organization ID. :param project_id: Filter by Project ID. :param name: Filter by the namespace name (exact match). :return:
List[Namespace]
Usage:
result = api.list_namespaces_all()
Types
The project is coded with Python, so don’t hesitate to take advantage of it.
All types of a product are stored in the scaleway.product.version namespace. For instance,
scaleway.registry.v1.Image
.
Logging
We are using the standard Python logging library. You can configure it as you wish:
import logging
logger = logging.getLogger("scaleway")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)