Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQLAlchemy to connect to OracleDB using python-oracledb instead of cx_Oracle

I am trying to create an engine using the python-oracledb library instead of cx_Oracle but it shows cx_Oracle module not found. Is there any way I can make sqlalchemy create an engine using python-oracledb?

I used to create an engine with the following if I was using cx_Oracle:

conn_str = "oracle+cx_oracle://{user}:{password}@{host}:{port}"

I am using the below code to make it use python-oracledb.

import oracledb
from sqlalchemy import create_engine, text

oracledb.init_oracle_client()

engine = create_engine(f'oracle://{p_username}:{p_password}@{p_dns}:{p_port}', max_identifier_length=128)

print(engine)
like image 405
hootowl Avatar asked Oct 11 '25 10:10

hootowl


1 Answers

oracle://… is equivalent to oracle+cx_oracle://…. As mentioned in the documentation, if you want to use python-oracledb you need to specify oracle+oracledb://…

like image 170
Gord Thompson Avatar answered Oct 14 '25 03:10

Gord Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!