Overview

About the FluidStack Software Development Kit for Python applications

FluidStack’s Python SDK assists in developing applications in Python using the FluidStack API.

It includes the following features:

Async client

The SDK exports an async client for making non-blocking calls to our API.

Example
1from FluidStack.client import AsyncFluidStack
2
3client = AsyncFluidStack(
4 api_key = '<your_api_key>'
5)
6
7async def main() -> None:
8 await client.ssh_keys.create(
9 name = 'my_ssh_key_name',
10 public_key = '<public key>',
11 )
12asyncio.run(main())

Exception handling

All errors thrown by the SDK are subclasses of ApiError.

Example
1import FluidStack
2
3try:
4 client.instance.list()
5except fluidstack.core.ApiError as e: # Handle all errors
6 print(e.status_code)
7 print(e.body)

Advanced

Timeouts

By default, requests will time out after 60 seconds. Configure the timeout duration with the timeout_in_seconds option at the client or request level.

Example
1from FluidStack.client import FluidStack
2
3client = FluidStack(
4 ...,
5 # All timeouts are 20 seconds
6 timeout=20.0,
7)
8
9# Override timeout for a specific method
10client.auth.get_callback(..., {
11 timeout_in_seconds=20.0
12})

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

Example
1client.auth.get_callback(..., {
2 max_retries=1
3})

Custom HTTP client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

Example
1import httpx
2
3from FluidStack.client import FluidStack
4
5client = FluidStack(...,
6 http_client=httpx.Client(
7 proxies='http://my.test.proxy.example.com',
8 transport=httpx.HTTPTransport(local_address='0.0.0.0'),
9 ),
10)

Beta status

This SDK is in Preview, and there may be breaking changes between versions without a major version update.

To ensure a reproducible environment (and minimize risk of breaking changes), we recommend pinning a specific package version.