Retrieve the Database connection details in python notebook.

Obireddy
Level 2
Retrieve the Database connection details in python notebook.

Hi Team,

As of now, Presto connection established in Dataiku to access from Database. but how can we retrieve those connection details into jupyter notebooks as variables to use them for making another connections.

Thanks in Advance.

0 Kudos
7 Replies
Turribeach

I am not really sure what you are trying to achieve here so can you please describe your requirement properly? If you have a Dataiku connection then you would normally create datasets from that connection on the flow and then create recipes that update those datasets. Then on a Jupyter Notebook you can access these datasets. 

0 Kudos
Obireddy
Level 2
Author

Hi,

 

Let me explain the problem clearly,

1)We have presto connection to access Database by providing all required  details.

2)Able to create datasets and load data  from database.

3)now want to retrieve the presto connection details like credentials and port number and  host details in jupyter notebook  for another purpose.

will it be possible ?

 

Thanks in advance.

 

regards,

Obireddy

0 Kudos
Turribeach

will it be possible? Yes!

for another purpose => What purpose? As that can change how you get the details. 

0 Kudos
Obireddy
Level 2
Author

another purpose means, want to invoke external(API/DB) connection with same Presto connection details.

like conn=api.connect(host= ,port= ,auth=(user,password)

cur=conn.cursor()

here in conn() host, port ,auth details need to same as Presto connection details.

So how can I fetch those details into jupyter notebook or python recipe ?

 

0 Kudos
Turribeach

Yeah this should do it:

 

import dataiku
client = dataiku.api_client()
connection_handle = client.get_connection('some_connection_name')
connection_definition = connection_handle.get_definition()
print(connection_definition)

 

 

0 Kudos
Obireddy
Level 2
Author

Thank you. I am able to fetch Presto connection details in Jupyter notebook.

But when I try to invoke API connection using same Presto details, getting error as Dss connection has no attribute cursor.

my code as  below:

import dataiku

client=dataiku.api_client()

connection_handle=client.get_connection('my_connection')

 

import sqlite

conn=(provided all details from connection_handle)

conn.cursor() #here I am getting error like  Dss connection has no attribute cursor.

 

So how can we make cursor() available for Dataiku to interact with other connections?

or can we make any changes to existing Presto connection which also enable cursor() functionality?

 

Please suggest.

 

 

 

0 Kudos
Turribeach

Please:

  1. Please post your actual code (you can replace any secret data with xxx or whatever
  2. Please post the full error with the full stsck trace
  3. Please use a Code section in your post so the code is correctly formatted (look for the </> icon when writting the post) 

Thanks

0 Kudos