Quickstart
1. Install the Python SDK
Our Python SDK is included with the Anyscale CLI. You can install it from pip.
pip install anyscale
2. Authentication
Anyscale authenticates API requests using a token. This token is the same as your CLI token, which can be found at https://console.anyscale.com/credentials. If you install your token on your filesystem, the SDK uses it automatically. If the token is set in the ANYSCALE_CLI_TOKEN
environment variable, then it, and prefer the environment variable over the credentials file.
from anyscale import AnyscaleSDK
sdk = AnyscaleSDK() # will read auth_token from ~/.anyscale/credentials.json
Note that you can also supply a token to the SDK: sdk = AnyscaleSDK("your_token_here")
.
Be sure to keep your auth token private and secure to prevent unwanted access to your Anyscale resources.
3. Test it out
To verify that everything is working, try creating a new Project using the SDK.
from anyscale import AnyscaleSDK
sdk = AnyscaleSDK()
create_project_response = sdk.create_project({
"name": "test-sdk-project",
"description": "Created from the Anyscale SDK"
})
print(f"Project created successfully: https://console.anyscale.com/projects/{create_project_response.result.id}")
If everything is working, you should see the success statement as output.
Project created successfully: https://console.anyscale.com/projects/prj_1234
4. Next Steps
After you have successfully set up the Python SDK, you may start interacting with Anyscale from your Python scripts. Please note that only AnyscaleSDK
and imports under anyscale.sdk
are considered public.