Skip to main content

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, which can be issued either via anyscale login command in the CLI or via Generate API Token.

  • Use anyscale login The CLI command fetches and updates the token in the local credential file (~/.anyscale/credentials.json). The SDK will use this token to authenticate its requests. This is recommended for interactive development.

  • Use ANYSCALE_CLI_TOKEN environment variable Manually generate your API Token here and set it in this environment variable. The SDK checks the environment variable first before the credentials file. This is recommended for CI/CD integration and other production use case.

note

Tokens issued by anyscale login expire after 7 days. If you want them to persist longer or not to expire, use --expire-in-days=<# of days> or --no-expire flags.

from anyscale import AnyscaleSDK

sdk = AnyscaleSDK() # will read the token from ~/.anyscale/credentials.json

Note that you can also supply a token to the SDK: sdk = AnyscaleSDK("your_token_here").

caution

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.