ipython-sql
ipython-sql copied to clipboard
Database URL visible by default: how to anonymise
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?
import getpass
password = getpass.getpass()
...
%sql postgresql://user:$password@host:port/db
@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