How to use the Python SDK
Prerequisites
- An API key
- Familiarity with command-line tools
- Basic familiarity with Python; Python 3+ installed
Installation
Our Python SDK is hosted at the Python Package Index (PyPI). You can use any Python package manager, such as pip or poetry.
For example, you can add this dependency to your project’s build file:
Instantiate a client
Import FluidStack
and instantiate a client with your API key:
Now you can use the client to consume the API from your Python application.
Warning
Avoid placing your API key in any file that might be shared with others. For information on using a .env
file instead of adding the API key directly into a file, see: API Overview - Secure use of your API key.
Use the FluidStack client in your app
The FluidStack client simplifies making API requests. It stores the API key that you used to instantiate it, and it already knows our API server’s base URL, so you can omit those details in your requests.
The SDK also provides code hints, type hints, parameter information, and other useful functions to speed up development.
For example, compare the tabs below:
You can see that instead of using requests
or a similar module to send an HTTP request and including the endpoint path and headers each time, the FluidStack client simplifies the request for you.
Call endpoints
Requests to API endpoints are implemented in the SDK as methods of the client. For example, the GET /instances endpoint is implemented like this:
The code shown above does not do anything with the response from the endpoint. It is up to you to handle the response.
For example, you could simply print the entire response to the terminal:
Or you could loop through the list and print only the name and status for each instance:
See the Programmatic Instance Management tutorial for more information on using Python, TypeScript, and their respective SDKs.
Instances
List user instances
Create an instance
Fetch an instance
Stop an instance
Start an instance
Terminate an instance
Parameters: None.
SSH Keys
List SSH keys
Add an SSH key
Delete an SSH key
Parameters: None.
List available configurations and operating system templates
Configurations
OS Templates
Parameters: None.