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

secure database credentials

Open christophlingg opened this issue 10 years ago • 7 comments

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

christophlingg avatar Jun 04 '15 09:06 christophlingg

+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 avatar Jun 16 '15 16:06 AndreaCrotti

@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

christophlingg avatar Jun 16 '15 16:06 christophlingg

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..

AndreaCrotti avatar Jun 16 '15 16:06 AndreaCrotti

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

invisiblefunnel avatar Aug 20 '15 06:08 invisiblefunnel

I was browsing for the same, @invisiblefunnel solution is what I was looking for. adding a note to the README would be great.

mottalrd avatar Oct 08 '15 10:10 mottalrd

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

eshilts avatar Feb 23 '16 04:02 eshilts

This is a great feature, I see that it has been merged but I think we don't get it with pip install, right?

tosolveit avatar Mar 07 '17 16:03 tosolveit