ipython-sql icon indicating copy to clipboard operation
ipython-sql copied to clipboard

Database URL visible by default: how to anonymise

Open TobiasSkovgaardJepsen opened this issue 6 years ago • 2 comments

I am in the situation where I want to possibly make my notebooks publicly available, but I am concerned with the visibility of the connection string. Currently the following happens when I load (values anonymized):

In [1]: %sql $DATABASE_CONNECTION_STRING
Out[1]: 'Connected: user@database'

Not that bad, but when executing queries (values anonymized):

In [2]: %%sql result <<
        SELECT * FROM table t;
Out[3]: * postgres://user:***@194.210.166.48:5432/database
        1 rows affected.
        Returning data to local variable result

a lot more information is printed.

Currently, I use %%capture to silence the output and display the result (stored in a variable) in a different cell. This works, but has to be done for each individual cell and is easy to forget. Is there anyway to disable this information globally?

TobiasSkovgaardJepsen avatar Sep 19 '18 07:09 TobiasSkovgaardJepsen

import getpass
password = getpass.getpass()

...

%sql postgresql://user:$password@host:port/db

kannes avatar Jun 18 '19 12:06 kannes

@TobiasSkovgaardJepsen, I would recommend you to install the nbstripout package which filters away all notebook outputs when you push a notebook to a github repo.

Link: https://github.com/kynan/nbstripout

emirlej avatar Aug 28 '19 11:08 emirlej