Any help would be most appreciated. I have a connect engine using sqlalchemy, which connects perfectly. I would like to make it dynamic where a user provides the info in a tkinter Entry box and that information gets parsed into a dict which in turn gets called by a function and the engine is created from there.
My working engine is:
engine = sqlalchemy.create_engine('postgresql+pg8000://myuser:mypass@localhost/mydb')
I would like something like this
sqlalchemy.create_engine('postgresql+pg8000://DBUSER:DBPASS@DBHOST/DBNAME')
where the variables are first supplied by tkinter Entry and placed into a dict, then read by the connection function.
I have the following
from sqlalchemy import create_engine
from sqlalchemy.engine import url
"""
These vars below are for testing. Ultimately they will be resolved
by a get() from tkinter which will take the values entered by a
user into an Entry widget and place them into the dict below.
The db_connect() func should build the url from the dict.
"""
DBNAME = 'mydb'
DBUSER = 'myuser'
DBPASS = 'password'
DBHOST ='localhost'
PNUM = '5432'
import json
import urllib.request as myurl
DATABASE = {
'drivername': 'postgres+pg8000',
'host': DBHOST,
'port': PNUM,
'username': DBUSER,
'password': DBPASS,
'database': DBNAME
}
def db_connect():
create_engine(url(DATABASE))
"""This func should create the db engine connect
connect = sqlalchemy.create_engine(db_connect())
df = pd.read_sql("SELECT * FROM nc_data",con=connect)
I get the error
db_connect return create_engine(url(DATABASE)) TypeError: 'module' object is not callable