ipython-sql
ipython-sql copied to clipboard
secure database credentials
Hello!
we are sharing our notebooks on github and want to avoid commiting our db credentials. Therefore we want to use environment variables. Is there any chance to do so:
%sql postgresql://db_user:db_passwd@localhost:db_port/dbname
normally you can use :variable to read variables, but this case is special
+1 on this @christophlingg
What do you mean by using :variable anyway? I think it's an issue with the Ipython magic things more in general, is that correct?
@AndreaCrotti on the readme you can find an example for :variable
In [12]: name = 'Countess'
In [13]: %sql select description from character where charname = :name
Ah ok I see.. Anyway I think the file that needs some changes for this to work is:
https://github.com/catherinedevlin/ipython-sql/blob/master/src/sql/magic.py
I was trying now to do some debugging but trying to put an ipdb there doesn't seem to work, it should not be too hard though..
I was wondering the same thing and found this related post. Here's how to pass database creds from an environment variable:
%load_ext sql
from os import environ
db_url = environ['DATABASE_URL']
%sql $db_url
I was browsing for the same, @invisiblefunnel solution is what I was looking for. adding a note to the README would be great.
I ran into this same issue. Thanks, @invisiblefunnel for the solution. I submitted a PR with that solution in the README. https://github.com/catherinedevlin/ipython-sql/pull/52
This is a great feature, I see that it has been merged but I think we don't get it with pip install, right?