Skip to content

Commit 39ce333

Browse files
Doc and collateral updates.
1 parent a30186e commit 39ce333

File tree

7 files changed

+150
-84
lines changed

7 files changed

+150
-84
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
11
# python-oracledb
22

3-
python-oracledb is a [Python programming language][python] extension module
3+
Python-oracledb is a [Python programming language][python] extension module
44
allowing Python programs to connect to [Oracle Database][oracledb].
5-
Python-oracledb is the new name for Oracle's popular cx_Oracle driver.
5+
Python-oracledb is the new name for the obsolete cx_Oracle driver.
6+
7+
Python-oracledb uses the same Python DB API as cx_Oracle, and has many new
8+
features.
69

710
The module conforms to the [Python Database API 2.0 specification][pep249] with
811
a considerable number of additions and a couple of minor exclusions, see the
912
[feature list][features].
1013

1114
Synchronous and [concurrent][concurrent] coding styles are supported.
1215

16+
Python-oracledb is available under an open source license, see below.
17+
1318
## Installation
1419

15-
Run `python -m pip install oracledb`
20+
Run:
21+
22+
```
23+
python -m pip install oracledb --upgrade
24+
```
25+
26+
See [python-oracledb Installation][installation] for details.
27+
28+
## Samples
29+
30+
Examples can be found in the [/samples][samples] directory and the
31+
[Python and Oracle Database Tutorial][tutorial].
1632

17-
See [python-oracledb Installation][installation].
33+
A basic example:
34+
35+
```
36+
import oracledb
37+
import getpass
38+
39+
un = "scott"
40+
cs = "localhost/orclpdb"
41+
# cs = "localhost/freepdb1" # for Oracle Database Free users
42+
# cs = "localhost/orclpdb1" # some databases may have this service
43+
pw = getpass.getpass(f"Enter password for {un}@{cs}: ")
44+
45+
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
46+
with connection.cursor() as cursor:
47+
sql = "select sysdate from dual"
48+
for r in cursor.execute(sql):
49+
print(r)
50+
```
1851

1952
## Dependencies and Interoperability
2053

@@ -52,11 +85,6 @@ See [python-oracledb Installation][installation].
5285
See the [python-oracledb Documentation][documentation] and [Release
5386
Notes][relnotes].
5487

55-
## Samples
56-
57-
Examples can be found in the [/samples][samples] directory and the
58-
[Python and Oracle Database Tutorial][tutorial].
59-
6088
## Help
6189

6290
Questions can be asked in [GitHub Discussions][ghdiscussions].

doc/src/user_guide/appendix_c.rst

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Specification.
3232
cx_Oracle always runs in a Thick mode using Oracle Client libraries. The
3333
features in python-oracledb Thick mode and cx_Oracle 8.3 are the same, subject
3434
to the :ref:`new features <releasenotes>`, some :ref:`deprecations
35-
<deprecations>`, and to other changes noted in this section.
35+
<deprecations>`, and to other changes noted in the documentation.
3636

3737
Oracle Client Library Loading Differences from cx_Oracle
3838
--------------------------------------------------------
@@ -187,8 +187,9 @@ SessionPool Object Differences
187187
The SessionPool object (which is an alias for the :ref:`ConnectionPool object
188188
<connpool>`) differences between the python-oracledb and cx_Oracle drivers are:
189189

190-
- A Python type() will show the class as ``oracledb.ConnectionPool`` instead
191-
of ``cx_Oracle.SessionPool``.
190+
- A Python `type() <https://docs.python.org/3/library/functions.html#type>`__
191+
will show the class as ``oracledb.ConnectionPool`` instead of
192+
``cx_Oracle.SessionPool``.
192193

193194
- A new boolean attribute, ``SessionPool.thin`` (see
194195
:attr:`ConnectionPool.thin`) is available. This attribute is *True* if the
@@ -374,33 +375,46 @@ Example error messages are:
374375
Upgrading from cx_Oracle 8.3 to python-oracledb
375376
===============================================
376377

377-
This section provides the detailed steps needed to upgrade from the obsolete
378-
cx_Oracle driver to python-oracledb.
379-
380378
Things to Know Before the Upgrade
381379
---------------------------------
382380

383381
Below is a list of some useful things to know before upgrading from cx_Oracle
384382
to python-oracledb:
385383

386384
- You can have both cx_Oracle and python-oracledb installed, and can use both
387-
in the same application.
385+
in the same application. Install python-oracledb like::
386+
387+
python -m pip install oracledb --upgrade
388+
389+
See :ref:`installation` for details.
390+
391+
- By default, python-oracledb runs in a 'Thin' mode which connects directly to
392+
Oracle Database. This mode does not need Oracle Client libraries to be
393+
installed. However, some additional functionality is available when
394+
python-oracledb uses them. Python-oracledb is said to be in 'Thick' mode
395+
when Oracle Client libraries are used. The Thick mode is equivalent to
396+
cx_Oracle.
388397

389-
- If you only want to use the python-oracledb driver in Thin mode, then you do
390-
not need Oracle Client libraries such as from Oracle Instant Client. You
391-
only need to :ref:`install <installation>` the driver itself::
398+
- python-oracledb Thin and Thick modes have the same level of support for the
399+
`Python Database API specification <https://peps.python.org/pep-0249/>`_ and
400+
can be used to connect to on-premises databases and Oracle Cloud
401+
databases. See :ref:`driverdiff`.
392402

393-
python -m pip install oracledb
403+
Examples can be found in the `GitHub samples directory
404+
<https://github.com/oracle/python-oracledb/tree/main/samples>`__. A basic
405+
example is:
394406

395-
See :ref:`driverdiff`.
407+
.. code-block:: python
408+
409+
import oracledb
410+
import getpass
396411
397-
- python-oracledb Thin and Thick modes have the same level of support for
398-
the `Python Database API specification <https://peps.python.org/pep-0249/>`_
399-
and can be used to connect to on-premises databases and Oracle Cloud
400-
databases. However, python-oracledb Thin mode does not support some
401-
advanced Oracle Database features such as Application Continuity (AC),
402-
Continuous Query Notification (CQN), and Sharding. See :ref:`Features
403-
Supported <featuresummary>` for details.
412+
pw = getpass.getpass(f"Enter password for hr@localhost/orclpdb: ")
413+
414+
with oracledb.connect(user="hr", password=userpwd, dsn="localhost/orclpdb") as connection:
415+
with connection.cursor() as cursor:
416+
for r in cursor.execute("select sysdate from dual"):
417+
print(r)
404418
405419
- python-oracledb can be used in SQLAlchemy, Django, Pandas, Superset and other
406420
frameworks and Object-relational Mappers (ORMs). To use python-oracledb in
@@ -414,17 +428,19 @@ to python-oracledb:
414428

415429
.. code-block:: python
416430
417-
oracledb.connect(user="scott", password=pw, dsn="localhost/orclpdb")
431+
connection = oracledb.connect(user="scott", password=pw, dsn="localhost/orclpdb")
418432
419433
This no longer works:
420434

421435
.. code-block:: python
422436
423-
oracledb.connect("scott", pw, "localhost/orclpdb")
437+
connection = oracledb.connect("scott", pw, "localhost/orclpdb")
424438
425439
- Some previously deprecated features are no longer available. See
426440
:ref:`deprecations`.
427441

442+
- There are many new features, see the :ref:`release notes <releasenotes>`.
443+
428444
.. _commonupgrade:
429445

430446
Steps to Upgrade to python-oracledb
@@ -577,8 +593,8 @@ following steps:
577593
Additional Upgrade Steps to use python-oracledb Thin Mode
578594
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
579595

580-
To use python-oracledb Thin mode, the following changes need to be made in
581-
addition to the common :ref:`commonupgrade`:
596+
To upgrade from cx_Oracle to python-oracledb Thin mode, the following changes
597+
need to be made in addition to the common :ref:`commonupgrade`:
582598

583599
1. Remove calls to :func:`~oracledb.init_oracle_client` since this turns on
584600
python-oracledb Thick mode.
@@ -635,7 +651,7 @@ addition to the common :ref:`commonupgrade`:
635651
:ref:`oraaccess.xml <optclientfiles>` files. The Thin mode lets equivalent
636652
properties be set in the application when connecting.
637653

638-
6. To use python-oracledb Thin mode in an ORACLE_HOME database installation
654+
6. To use python-oracledb Thin mode in an ``ORACLE_HOME`` database installation
639655
environment, you must use an explicit connection string since the
640656
``ORACLE_SID``, ``TWO_TASK``, and ``LOCAL`` environment variables are not
641657
used. They are used in Thick mode.
@@ -664,8 +680,8 @@ addition to the common :ref:`commonupgrade`:
664680
Additional Upgrade Steps to use python-oracledb Thick Mode
665681
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
666682

667-
To use python-oracledb Thick mode, the following changes need to be made in
668-
addition to the common :ref:`commonupgrade`:
683+
To upgrade from cx_Oracle to python-oracledb Thick mode, the following changes
684+
need to be made in addition to the common :ref:`commonupgrade`:
669685

670686
1. The function :func:`oracledb.init_oracle_client()` *must* be called to
671687
enable python-oracle Thick mode. It can be called anywhere before the first

doc/src/user_guide/connection_handling.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,8 @@ known to python-oracledb are discarded and not passed to the database.
633633

634634
.. _pyoparams:
635635

636-
Python-oracledb Parameters Settable in Easy Connect Strings or Central Configuration Providers
637-
----------------------------------------------------------------------------------------------
636+
Python-oracledb Parameters Settable in Easy Connect Strings or Centralized Configuration Providers
637+
--------------------------------------------------------------------------------------------------
638638

639639
Some python-oracledb connection and pool creation parameters can be set in
640640
:ref:`Easy Connect strings <easyconnect>` or via a :ref:`Centralized

doc/src/user_guide/installation.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ Python-oracledb is typically installed from Python's package repository
6565

6666
.. code-block:: python
6767
68-
import getpass
69-
7068
import oracledb
69+
import getpass
7170
72-
un = 'scott'
73-
cs = 'localhost/orclpdb'
74-
pw = getpass.getpass(f'Enter password for {un}@{cs}: ')
71+
un = "scott"
72+
cs = "localhost/orclpdb"
73+
# cs = "localhost/freepdb1" # for Oracle Database Free users
74+
# cs = "localhost/orclpdb1" # some databases may have this service
75+
pw = getpass.getpass(f"Enter password for {un}@{cs}: ")
7576
7677
with oracledb.connect(user=un, password=pw, dsn=cs) as connection:
7778
with connection.cursor() as cursor:
78-
sql = """select sysdate from dual"""
79+
sql = "select sysdate from dual"
7980
for r in cursor.execute(sql):
8081
print(r)
8182
@@ -131,8 +132,8 @@ In python-oracledb Thick mode, Oracle Database's standard client-server network
131132
interoperability allows connections between different versions of Oracle Client
132133
libraries and Oracle Database. For current or previously certified
133134
configurations, see Oracle Support's `Doc ID 207303.1
134-
<https://support.oracle.com/epmos/faces/DocumentDisplay?id=207303.1>`__. In
135-
summary:
135+
<https://support.oracle.com/knowledge/Oracle%20Database%20Products/207303_1.html>`__.
136+
In summary:
136137

137138
- Oracle Client 23 can connect to Oracle Database 19 or later
138139
- Oracle Client 21 can connect to Oracle Database 12.1 or later

doc/src/user_guide/sql_execution.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,9 @@ support makes use of `Apache nanoarrow <https://arrow.apache.org/nanoarrow/>`__
816816
libraries to build data frames.
817817

818818
The following data type mapping occurs from Oracle Database types to the Arrow
819-
types used in OracleDataFrame objects. Querying any other data types from
820-
Oracle Database will result in an exception.
819+
types used in OracleDataFrame objects. Querying any other data types from
820+
Oracle Database will result in an exception. :ref:`Output type handlers
821+
<outputtypehandlers>` cannot be used to map data types.
821822

822823
.. list-table-with-summary::
823824
:header-rows: 1

samples/async_gather.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2+
# Copyright (c) 2023, 2025, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -27,55 +27,67 @@
2727
#
2828
# Demonstrates using a connection pool with asyncio and gather().
2929
#
30-
# Multiple database sessions will be opened and used by each coroutine. The
31-
# number of connections opened can depend on the speed of your environment.
30+
# This also shows the use of pool_alias for connection pool caching, so the
31+
# pool handle does not need to passed through the app.
32+
#
33+
# Each coroutine invocation will acquire a connection from the connection pool.
34+
# The number of connections in the pool will depend on the speed of your
35+
# environment. In some cases existing connections will get reused. In other
36+
# cases up to CONCURRENCY connections will be created by the pool.
3237
# -----------------------------------------------------------------------------
3338

3439
import asyncio
3540

3641
import oracledb
3742
import sample_env
3843

44+
# Pool name for the connection pool cache
45+
POOL_ALIAS_NAME = "mypool"
46+
3947
# Number of coroutines to run
4048
CONCURRENCY = 5
4149

4250
# Query the unique session identifier/serial number combination of a connection
43-
SQL = """SELECT UNIQUE CURRENT_TIMESTAMP AS CT, sid||'-'||serial# AS SIDSER
44-
FROM v$session_connect_info
45-
WHERE sid = SYS_CONTEXT('USERENV', 'SID')"""
51+
SQL = """select unique current_timestamp as ct, sid||'-'||serial# as sidser
52+
from v$session_connect_info
53+
where sid = sys_context('userenv', 'sid')"""
4654

4755

4856
# Show the unique session identifier/serial number of each connection that the
49-
# pool opens
57+
# pool creates
5058
async def init_session(connection, requested_tag):
5159
res = await connection.fetchone(SQL)
5260
print(res[0].strftime("%H:%M:%S.%f"), "- init_session SID-SERIAL#", res[1])
5361

5462

5563
# The coroutine simply shows the session identifier/serial number of the
56-
# connection returned by the pool.acquire() call
57-
async def query(pool):
58-
async with pool.acquire() as connection:
64+
# connection returned from the pool
65+
async def query():
66+
async with oracledb.connect_async(
67+
pool_alias=POOL_ALIAS_NAME
68+
) as connection:
5969
await connection.callproc("dbms_session.sleep", [1])
6070
res = await connection.fetchone(SQL)
6171
print(res[0].strftime("%H:%M:%S.%f"), "- query SID-SERIAL#", res[1])
6272

6373

6474
async def main():
65-
pool = oracledb.create_pool_async(
75+
oracledb.create_pool_async(
6676
user=sample_env.get_main_user(),
6777
password=sample_env.get_main_password(),
6878
dsn=sample_env.get_connect_string(),
6979
params=sample_env.get_pool_params(),
7080
min=1,
7181
max=CONCURRENCY,
7282
session_callback=init_session,
83+
pool_alias=POOL_ALIAS_NAME,
7384
)
7485

75-
coroutines = [query(pool) for i in range(CONCURRENCY)]
86+
coroutines = [query() for i in range(CONCURRENCY)]
7687

7788
await asyncio.gather(*coroutines)
7889

90+
pool = oracledb.get_pool(POOL_ALIAS_NAME)
7991
await pool.close()
8092

8193

0 commit comments

Comments
 (0)