3. Connecting to Oracle Database¶
select_ai uses the Python thin driver i.e. python-oracledb
to connect to the database and execute PL/SQL subprograms.
3.1. Synchronous connection¶
To connect to an Oracle Database synchronously, use
select_ai.connect() method as shown below
import select_ai
user = "<your_db_user>"
password = "<your_db_password>"
dsn = "<your_db_dsn>"
select_ai.connect(user=user, password=password, dsn=dsn)
3.2. Asynchronous connection¶
Asynchronous applications should use select_ai.async_connect() along
with await keyword:
import select_ai
user = "<your_db_user>"
password = "<your_db_password>"
dsn = "<your_db_dsn>"
await select_ai.async_connect(user=user, password=password, dsn=dsn)
3.3. Connection Pool¶
You can create a connection pool using the select_ai.create_pool
and select_ai.create_pool_async methods
import select_ai
user = "<your_db_user>"
password = "<your_db_password>"
dsn = "<your_db_dsn>"
# for sync pool
select_ai.create_pool(
user=user,
password=password,
dsn=dsn,
min_size=5,
max_size=10,
increment=5
)
# for async pool
select_ai.create_pool_async(
user=user,
password=password,
dsn=dsn,
min_size=5,
max_size=10,
increment=5
)
Check this blog which shows the benefit of connection pooling along with FastAPI service
Note
For m-TLS (wallet) based connection, additional parameters like
wallet_location, wallet_password, https_proxy,
https_proxy_port can be passed to the connect and async_connect
methods