1

I want to configure databricks-connect configure through python OS module after installing databricks-connect through os.system("pip install databricks-connect==6.5")

Once databricks-connect is successfully install we need to configure it by passing the following values:

host= "https://<location>.azuredatabricks.net",
port= "8787",
token = "<Token>",
cluster_id = "<ClusterId>",
org_id = "<OrgId>"

In the terminal if we type databricks-connect configure , it will start asking you above parameter one by one as shown in the figure:

enter image description here

Now I want same thing to be run using python os.system

os.system("pip install databricks-connect")
os.system("databricks-connect configure")

After this how to pass host, port, token etc.?
After every value we have to press enter as well.

when I run this on terminal this work fine ,

echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure

but giving me error when i try to run this python os.module

os.sytem("echo -e 'https://adb-661130381327abc.11.azuredatabricks.net\nxxxxx\n0529-yyyy-twins608\n6611303813275431\n15001' | databricks-connect configure")

Error "New host value must start with https://, e.g., https://demo.cloud.databricks.com")

1

2 Answers 2

2

You can just pipe the data as stdin to the program.

import os


host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
command = "echo '{}' | {}".format(stdin_string, "databricks-connect configure")
os.system(command)

Sign up to request clarification or add additional context in comments.

7 Comments

getting following error The system cannot find the file specified.
Just double-check if the command string is correct and if the order of arguments is ok. Try again. I had mistakenly malformed the command string.
command = "echo adb-8538834050545100.10.azuredatabricks.net | databricks-connect configure" , when i am running this host is getting updated , but how to pass multiple value.., i did tried above code but not working
for only first value i.e. host it is getting updated
; wont work. Try echo 'adb-8538834050545100.10.azuredatabricks.net\n8787\n<Token>\n<Cluster>\n<Org>' | databricks-connect configure
|
1

A small modification to @Anmol

import subprocess

host= "https://<location>.azuredatabricks.net"
port= "8787"
token = "<Token>"
cluster_id = "<ClusterId>"
org_id = "<OrgId>"

stdin_list = [host, port, token, cluster_id, org_id]
stdin_string = '\n'.join(stdin_list)
echo = subprocess.Popen((['echo', '-e', stdin_string]), stdout=subprocess.PIPE)
# fix typo from std_out to stdout
output = subprocess.check_output(('databricks-connect', 'configure'), stdin=echo.stdout)
echo.wait()
print(output.decode())
echo -e

takes care of the enter

1 Comment

Work for me, and there is typo in echo = subprocess.Popen((['echo', '-e', stdin_string]), std_out=subprocess.PIPE), should be stdout. I edited for you ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.