- This time we covered several core areas of the Oracle-Python bridge including PL/SQL stored procedure calls and handling PL/SQL function results. When it comes to Python, you should now be familiar with the essentials of the multiprocessing module which is one of the most important recent additions to the language. Finally, Oracle Berkeley DB.
- As a first step, get familiar with the basic concepts of Oracle-Python connectivity. Among the core principles of Python's way of doing things there is a rule about having high-level interfaces to APIs. The Database API (in this case the Oracle API) is one example. Using the cxOracle Python module from Computronix, you can take command over.
Features
Easily installed from PyPI.
Support for Python 3.6 and higher. Older versions of cx_Oracle may be used with previous Python releases.
Support for Oracle Client 11.2, 12, 18, 19 and 21. Oracle's standard cross-version interoperability, allows easy upgrades and connectivity to different Oracle Database versions.
Connect to Oracle Database 9.2, 10, 11, 12, 18, 19 or 21 (depending on the Oracle Client version used).
SQL and PL/SQL Execution. The underlying Oracle Client libraries have significant optimizations including compressed fetch, pre-fetching, client and server result set caching, and statement caching with auto-tuning.
Full use of Oracle Network Service infrastructure, including encrypted network traffic and security features.
Extensive Oracle data type support, including large object support (CLOB and BLOB).
Direct binding to SQL objects. One great use case is binding Python objects to Oracle Spatial SDO objects.
SODA (Simple Oracle Document Access)
Array operations for efficient INSERT and UPDATEs.
Array row counts and batch error handling for array operations.
Fetching of large result sets.
REF CURSOR support.
Support for scrollable cursors. Go back and forth through your query results.
Fetch PL/SQL Implicit Results. Easily return query results from PL/SQL.
Row Prefetching. Efficient use of the network.
Client Result Caching. Improve performance of frequently executed look-up statements.
Support for Advanced Queuing. Use database notifications to build micro-service applications.
Continuous Query Notification (CQN). Get notified when data changes.
Support for Edition Based Redefinition. Easily switch applications to use updated PL/SQL logic.
Support for setting application context during the creation of a connection, making application metadata more accessible to the database, including in LOGON triggers.
End-to-end monitoring and tracing.
Transaction Management.
Session Pooling, with tagging and session state fix-up callback.
Database Resident Connection Pooling (DRCP).
Privileged Connections.
External Authentication.
Database startup and shutdown.
Sharded Databases.
Oracle Database High Availability Features, such as FAN notifications and Transaction Guard support.
Python is a popular general purpose dynamic scripting language. With the rise of Frameworks, Python is also becoming common for Web application development. If you want to use Python and an Oracle database, this tutorial helps you get started by giving examples. It is recommended that you complete this OBE first. Python is a popular general purpose dynamic scripting language. With the rise of Frameworks, Python is also becoming common for Web application development. If you want to use Python and an Oracle database, this tutorial helps you get started by giving examples. It is recommended that you complete this OBE first.
DB API specification exclusions: The time data type is not supported by Oracle and is therefore not implemented. The method cursor.nextset()
is not implemented either as the DB API specification assumes an implementation of cursors that does not fit well with Oracle's implementation of cursors and implicit results. See the method cursor.getimplicitresults() for more information.
Table of Contents
About Python on Oracle Linux
There are several ways to get started with Python development on Oracle Linux. Oracle Linux yum server offers updates for system Python included with Oracle Linux as well as new versions of Python via the Software Collection Library (SCL) and EPEL (Oracle Linux 7 only). The different Python versions available and the corresponding repository and RPM names are summarized in the tables below.
Oracle Driver Class Name
Oracle Linux 8 | |
Python Version | AppStream Module |
---|---|
3.8 | python38 |
3.6 | python36 |
2.7 | python27 |
Oracle Linux 7 | Repository: RPM name | ||
Python Version | Base Oracle Linux | Software Collection Library | EPEL |
---|---|---|---|
3.6 | ol7_latest: python3 | ol7_software_collections: rh-python36 | ol7_developer_EPEL: python36 |
3.5 | ol7_software_collections: rh-python35 | ||
3.4 | ol7_software_collections: rh-python34 | ol7_developer_EPEL: python34 | |
2.7 | ol7_latest: python |
Oracle Linux 6 | Repository: RPM name | |
Python Version | Base Oracle Linux | Software Collection Library |
---|---|---|
3.6 | ol6_software_collections: rh-python36 | |
3.5 | ol6_software_collections: rh-python35 | |
3.4 | ol6_software_collections: rh-python34 | |
2.6 | ol6_latest: python |
Installing Python
Enabling Required Repositories
The installation instructions below require different Oracle Linux yum server repositories configured, depending on what you are installing. For example, to enable the ol7_developer_EPEL and the ol7_oracle_instantclient repository:
$ sudo yum install -y oracle-epel-release-el7 oracle-release-el7
If yum is unable to find any of the packages mentioned below, follow the instructions on our Getting Started page to ensure your system is set up correctly to work with our release packages.
System Python
Python is an integral part of the Oracle Linux operating system. Oracle Linux 6 has Python 2.6 and Oracle Linux 7 has Python 2.7 already installed and includes Python 3 as of Oracle Linux 7.7. Python is not installed by default on Oracle Linux 8. Instead, different versions of Python can be installed via AppStreams.
About Support for Python 2
The Python Software Foundation, the community organization behind Python, has announced that the Python 2 series has reached end-of-life on January 1, 2020 with release 2.7. Because Oracle Linux is an enterprise Linux distribution, support decisions for components in the operating system are made independently from those made in the upstream community. Therefore, Python 2 remains supported in Oracle Linux as outlined below.
Continued support for Python 2 in Oracle Linux 7 and Oracle Linux 6
Python 2 remains supported in Oracle Linux 7 and Oracle Linux 6. As such, critical security errata and select high-impact critical bug fixes will be provided while Oracle Linux 7 and Oracle Linux 6 are covered under Oracle Linux Premier support as detailed in the Lifetime Support Policy
Continued support for Python 2 in Oracle Linux 8
Python 2 is delivered in Oracle Linux 8 via Application Streams and may optionally be installed. Python 2 is supported in Oracle Linux 8 and critical security errata and select high-impact critical bug fixes will be provided according to this Oracle Linux 8 Application Stream Life Cycle.
Installing Python 3 from the Oracle Linux 7 Latest Repository
Oracle Linux 7.7 and newer include Python 3.
To install Python 3 from the Oracle Linux 7 latest repository:
$ sudo yum install -y python3
Note that python3-devel is in the ol7_optional_latest repository. To install python3-devel:
$ sudo yum install -y --enablerepo ol7_optional_latest python3-devel
Installing Python From the EPEL for Oracle Linux 7 repository
Oracle Linux yum server hosts an EPEL (Extra Packages for Enterprise Linux) repository based on upstream Fedora EPEL. This repository includes recent versions of Python. You can install and use Python from EPEL on Oracle Linux using a virtual environment to isolate the newly installed Python interpreter, libraries and scripts from system Python.
To install and enable Python 3.6 in a virtual environment using venv, run:
$ sudo yum install -y oracle-epel-release-el7
$ sudo yum install -y python36
$ python3.6 -m venv py36env
$ source py36env/bin/activate
Installing Python From the Software Collection Library
The Software Collection Library (SCL) is intended for development environments which require access to the latest features of software components such as Perl, PHP, or Python. For these environments, it's important to minimize the disruption of system processes that rely on the versions of these components. The SCL enables you to install and use several versions of the same software on a system, simultaneously, and without disruption.
To install Python 3.6 from the SCL on Oracle Linux 7, install oracle-softwarecollection-release-el7 and then install scl-utils and rh-python36:
$ sudo yum install -y oracle-softwarecollection-release-el7
$ sudo yum -y install scl-utils rh-python36
To enable and use Python 3.6 from the SCL:
$ scl enable rh-python36 bash
$ python
Installing Python on Oracle Linux 8 via AppStream Modules
Oracle Linux 8 introduces the concept of Application Streams, where multiple versions of user-space components can be delivered and updated more frequently than the core operating system packages in RPM format or groups of related RPMs called Modules. Oracle Linux 8 offers several independently updated versions of Python via Module Streams.
To list available Module Streams for Python:
$ sudo yum module list | grep python
To install the Python 3.6 module and run Python 3.6:
$ sudo yum module install python36
$ python3
To use pip for installing additional Python modules:
$ python3 -m pip install <module name>
To create a virtual environment using venv:
$ python3 -m venv py36env
$ source py36env/bin/activate
cx_Oracle: Connecting Python to Oracle Database
cx_Oracle is a module that enables access to Oracle Database and conforms to the Python database API specification. For more details, see the cx_Oracle documentation
About Oracle Instant Client
cx_Oracle depends on Oracle Instant Client. On Oracle Linux yum server Oracle Instant Client 18.3 RPMs are in the ol7_oracle_instantclient and ol6_oracle_instantclient repositories. Assuming you have enabled the repository for Oracle Instant Client appropriate for your Oracle Linux release, it will be installed as a dependency. Be sure to set your environment such that cx_Oracle can find the required Oracle Instant Client libraries by following these steps. cx_Oracle is built with Oracle Client 18.3, which connects to Oracle Database 11.2 and greater. Older releases of Oracle Instant Client are available on OTN.
Installing cx_Oracle for Python 3 from the Oracle Linux 7 Latest Repository
To install cx_Oracle for Python 3 from the Oracle Linux 7 Latest Repository:
$ sudo yum -y install oraclelinux-developer-release-el7
$ sudo yum -y install python36-cx_Oracle
Installing cx_Oracle for System Python
The Oracle Linux 6 and 7 Developer repositories include cx_Oracle RPMs.* To install cx_Oracle for System Python on Oracle Linux 7, enable the ol7_developer repo and run:
$ sudo yum -y install oraclelinux-developer-release-el7
$ sudo yum -y install python-cx_Oracle
*) Note for Python 2.6, use the older cx_Oracle 5.2 release.
Installing cx_Oracle for Python from EPEL
At the moment, there are no cx_Oracle RPMs for Python from EPEL. However, you can install cx_Oracle via pip. Assuming you have installed and enabled Python 3.6 from EPEL in a virtual environment and installed InstantClient, as described above.
$ python -m pip install cx_Oracle
Installing cx_Oracle for Python from the Software Collection Library (SCL)
cx_Oracle RPM built to work with SCL Python versions are named according to the format:
Python Oracle Driver Ever Downloads Free
For example, to install the matching cx_Oracle RPM for Python 3.6 from SCL:
$ sudo yum -y install rh-python36-python-cx_Oracle
Important: Configuring Your Environment for Oracle Instant Client
Finally, for Oracle Instant Client releases before 19.x, you must set up the environment so that cx_Oracle can find the necessary libraries. For example, for Oracle Instant Client release 18.3:
$ sudo sh -c 'echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf'
$ sudo ldconfig
Support
Oracle Python Driver
Oracle Linux customers receive support for System Python and Python packages in the Software Collection Library. Community support is available in the Python and Oracle Developer Community.
References
Python Script Oracle
- Dev Gym: CRUD operations using cx_Oracle and Python
- Oracle Linux yum server FAQ: Configuring yum proxy