Connect Jypiter to my database


#1

Hi,
I need to be able to create tables in my database on cloud lab (hdfs?) by using Jupyter. In order to explain better what I mean I will give you a python code example of how i connected to my database in the past to demonstrate what i need.

db_name = “health_profiles”
userName = “jpasecnika4935”
passWord = “6RCTXXMU”

def connect(user, password, db, host=‘localhost’, port=5432):
‘’‘Returns a connection and a metadata object’’’
# We connect with the help of the PostgreSQL URL
# postgresql://federer:grandestslam@localhost:5432/tennis
url = ‘postgresql://{}:{}@{}:{}/{}’
url = url.format(user, password, host, port, db)

# The return value of create_engine() is our connection object
con = sqlalchemy.create_engine(url, client_encoding='utf8')

# We then bind the connection to MetaData()
meta = sqlalchemy.MetaData(bind=con, reflect=True)

return con, meta

con, meta = connect(‘jpasecnika4935’, ‘6RCTXXMU’, ‘’)

Can you please help? What would be the alternative for my case ? As I was going to then push files from python into hdfs and query them in Hue later