I have only added this code to the *ts file of this repository(https://github.com/ibdafna/webdash) which works fine in my conda environment.
from sqlalchemy.engine.create import create_engine
import pandas as pd
from datetime import datetime
url = 'postgresql://mmnikx ....'
engine =create_engine(url)
now = datetime.now()
df=pd.DataFrame([now])
df.to_sql(
"TestDBTime", # table name
con=engine,
if_exists='append',
index=False
)
I am trying to connect to a database using sqlalchemy. This piece of code is inside a typescript file. Running dash with pyodide inside a html file. I think the problem is that I can't load psycopg2 because it is not a pure python package and the pyodide version of sqlalchemy does not have this package.
How could I avoid this problem? My main problem is getting information. Connecting to a database seems to be the best option. I tried to install pygsheets, but no success.
Uncaught (in promise) PythonError: Traceback (most recent call last):
File "/lib/python3.9/site-packages/_pyodide/_base.py", line 415, in eval_code
CodeRunner(
File "/lib/python3.9/site-packages/_pyodide/_base.py", line 296, in run
coroutine = eval(self.code, globals, locals)
File "<exec>", line 19, in <module>
File "<string>", line 2, in create_engine
File "/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned
return fn(*args, **kwargs)
File "/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 560, in create_engine
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/lib/python3.9/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 782, in dbapi
import psycopg2
ModuleNotFoundError: No module named 'psycopg2'
at new_error (pyodide.asm.js:14:246344)
at pyodide.asm.wasm:0xe6e27
at pyodide.asm.wasm:0xe6f25
at Object.Module._pythonexc2js (pyodide.asm.js:14:943337)
at Object.Module.callPyObjectKwargs (pyproxy.gen.ts:409:12)
at Object.Module.callPyObject (pyproxy.gen.ts:415:17)
at PyProxyClass.apply (pyproxy.gen.ts:1191:19)
at Object.apply (pyproxy.gen.ts:1064:18)
at Object.runPython (api.ts:57:25)
at r (worker.js:62:35)