Get a database admin (Python)
The Data API clients use the Database Admin class to perform administrative operations, like managing keyspaces, within a specific database.
To perform administrative actions outside of a specific database, see Get an Astra DB admin (Python) instead.
The Database Admin class name varies by client.
The Python client uses AstraDBDatabaseAdmin.
|
You need an application token with permission to interact with the target database, such as the Database Administrator role. For more information, see Get endpoint and token. |
Result
Returns an AstraDBDatabaseAdmin object that can perform administrative actions on the specified database.
Signature
Use the get_database_admin method from the Database class.
get_database_admin(
*,
token: str | TokenProvider,
spawn_api_options: APIOptions,
) -> DatabaseAdmin
Alternatively, use the get_database_admin method from the AstraDBAdmin class.
get_database_admin(
api_endpoint_or_id: str,
*,
api_endpoint: str,
id: str,
region: str,
token: str | TokenProvider,
spawn_api_options: APIOptions,
) -> AstraDBDatabaseAdmin
Parameters
Parameters for the get_database_admin method from the Database class:
| Name | Type | Summary |
|---|---|---|
|
|
Optional. The token used by the resulting admin object. The token should have sufficient permissions to perform the desired downstream operations. Default: The token used by the object that called this method. |
|
Optional. A complete or partial specification of timeouts. If |
Parameters for the get_database_admin method from the AstraDBAdmin class:
| Name | Type | Summary |
|---|---|---|
|
|
An alternative to the |
|
|
The database’s API endpoint, typically formatted as If specified, you cannot specify |
|
|
The database’s ID. If specified, you must also specify |
|
|
The database’s region. If specified, you must also specify |
|
|
Optional. The token used by the resulting admin object. The token should have sufficient permissions to perform the desired downstream operations. Default: The token used by the object that called this method. |
|
Optional. A complete or partial specification of timeouts. If |
Examples
The following examples demonstrate how to get a database admin object.
Get a database admin from a database
from astrapy import DataAPIClient
# Get a database object
client = DataAPIClient()
database = client.get_database(
"API_ENDPOINT", token="APPLICATION_TOKEN"
)
# Get a database admin object
database_admin = database.get_database_admin()
Get a database admin from an admin
from astrapy import DataAPIClient
# Get an admin object
client = DataAPIClient("APPLICATION_TOKEN")
admin = client.get_admin()
# Get a database admin object
database_admin = admin.get_database_admin(api_endpoint="API_ENDPOINT")
Errors
For a full list of Data API error codes and their corresponding messages, see Data API errors and error codes.
For more information about how the client handles underlying Data API errors, see Python client error handling.
Client reference
For more information, see the client reference.