This package is a Python Implementation of the Databricks API for structured and programmatic use. This Python implementation requires that your Databricks API Token be saved as an environment variable in your system:export DATABRICKS_TOKEN=MY_DATABRICKS_TOKEN in OSX / Linux. Or in Windows by searching for System Environment Variables in the Start Menu and adding it in the editor. For details see this guide.
UPDATE
Tokens can now be passed when a particular class is instantiated. E.g.:
You can either use pip install databricksapi to install it globally, or you can clone the repository. Please note that only compatability with Python 3.7+ is guaranteed.
The Token API allows any user to create, list, and revoke tokens that can be used to authenticate and access Databricks REST APIs. Initial authentication to this API is the same as for all of the Databricks API endpoints.
url = 'https://url.for.databricks.net'
db_api = Token(url)
#token_id can be obtained from using the listTokens() method
db_api.revokeToken('5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4')
Secrets API
The Secrets API allows you to manage secrets, secret scopes, and access permissions.
The scope name must consist of alphanumeric characters, dashes, underscores, and periods, and may not exceed 128 characters. The maximum number of scopes in a workspace is 100.
Inserts a secret under the provided scope with the given name. If a secret already exists with the same name, this command overwrites the existing secret’s value. The server encrypts the secret using the secret scope’s encryption settings before storing it. You must have WRITE or MANAGE permission on the secret scope.
The value_type parameter can either be set to string or bytes depending on the type fo value the user passes in.
Lists the secret keys that are stored at this scope. This is a metadata-only operation; secret data cannot be retrieved using this API. Users need READ permission to make this call.
Creates or overwrites the ACL associated with the given principal (user or group) on the specified scope point. In general, a user or group will use the most powerful permission available to them
The Clusters API allows you to create, start, edit, list, terminate, and delete clusters via the API. The maximum allowed size of a request to the Clusters API is 10MB.
Creates a new Spark cluster. This method acquires new instances from the cloud provider if necessary. This method is asynchronous; the returned cluster_id can be used to poll the cluster state. When this method returns, the cluster is in a PENDING state. The cluster is usable once it enters a RUNNING state.
The worker_type can be either workers or autoscale. If a autoscale is set, then the min_workers and max_workers must be specified.
Terminates a Spark cluster given its id. The cluster is removed asynchronously. Once the termination has completed, the cluster will be in a TERMINATED state. If the cluster is already in a TERMINATING or TERMINATED state, nothing will happen.
Permanently deletes a Spark cluster. If the cluster is running, it is terminated and its resources are asynchronously removed. If the cluster is terminated, then it is immediately removed.
You cannot perform any action on a permanently deleted cluster and a permanently deleted cluster is no longer returned in the cluster list.
Returns information about all pinned clusters, currently active clusters, up to 70 of the most recently terminated interactive clusters in the past 30 days, and up to 30 of the most recently terminated job clusters in the past 30 days.
Unpinning a cluster will allow the cluster to eventually be removed from the list returned by the List API. Unpinning a cluster that is not pinned has no effect.
Retrieves the information for a cluster given its identifier. Clusters can be described while they are running, or up to 30 days after they are terminated.
Retrieves a list of events about the activity of a cluster. This API is paginated. If there are more events to read, the response includes all the parameters necessary to request the next page of events.
The cluster_type parameter can be one of existing or new.
runsList(run, run_type, job_id, offset, limit)
The run_type parameter must be one of completed or active.
DBFS API
The DBFS API is a Databricks API that makes it simple to interact with various data sources without having to include your credentials every time you read a file.
Methods
addBlock(data, handle)
closeStream(handle)
createFile(path, overwrite)
deleteFile(path, recursive)
getStatus(path)
listFiles(path)
makeDirs(path)
moveFiles(source_path, target_path)
putFiles(path, overwrite, files, contents=None)
readFiles(path, offset, length)
Groups API
The Groups API allows you to manage groups of users via the API. You must be a Databricks administrator to invoke this API.
Methods
addMember(parent_name, name, name_type)
createGroup(group_name)
listGroupMembers(group_name, return_type='json')
listGroups()
listParents(name, name_type)
removeMember(name, parent_name, name_type)
deleteGroup(group_name)
listGroupMembers(group_name, return_type='json')
The default return_type can be one of json or list, by default the paramter is set to json. This is provide to simplify pulling usernames from the default return time which can be cumbersome.
listParents(name, name_type)
The name_type parameter must be one of user or group.
removeMember(name, parent_name, name_type)
The name_type parameter must be one of user or group.
Instance Profiles API
The Instance Profiles API allows admins to add, list, and remove instance profiles that users can launch clusters with. Regular users can list the instance profiles available to them.
Methods
addProfile(profile_arn, skip_validation=None)
listProfiles()
removeProfile()
Libraries API
The Libraries API allows you to install and uninstall libraries and get the status of libraries on a cluster via the API.