Retrieve the Database connection details in python notebook.

Options
obireddy
obireddy Registered Posts: 13 ✭✭

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.

Tagged:

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    Options

    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.

  • obireddy
    obireddy Registered Posts: 13 ✭✭
    Options

    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

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    Options

    will it be possible? Yes!

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

  • obireddy
    obireddy Registered Posts: 13 ✭✭
    Options

    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 ?

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    edited July 17
    Options

    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)

  • obireddy
    obireddy Registered Posts: 13 ✭✭
    Options

    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.

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    Options

    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

Setup Info
    Tags
      Help me…