This article is the introductory part of a five-part series that covers how Python developers can leverage the power and functionality of Oracle Database to build high-performance, data-driven applications. Oracle Database is the world's most popular database, providing tremendous power and flexibility for efficient data management. Python, in turn, is an easy-to-use, open source and multiparadigm programming language with a wide variety of focus areas, including web development, data analysis, building games, system administration software development, and spatial and scientific applications. So, the omnipresence of Python and the power of Oracle Database, when combined, enable developing high-performance, data-driven applications in a broad range of fields.
|Published (Last):||12 March 2014|
|PDF File Size:||8.80 Mb|
|ePub File Size:||18.14 Mb|
|Price:||Free* [*Free Regsitration Required]|
This article is the introductory part of a five-part series that covers how Python developers can leverage the power and functionality of Oracle Database to build high-performance, data-driven applications. Oracle Database is the world's most popular database, providing tremendous power and flexibility for efficient data management.
Python, in turn, is an easy-to-use, open source and multiparadigm programming language with a wide variety of focus areas, including web development, data analysis, building games, system administration software development, and spatial and scientific applications.
So, the omnipresence of Python and the power of Oracle Database, when combined, enable developing high-performance, data-driven applications in a broad range of fields. Many modules designed to access different data sources are freely available for Python, each extending the language with advanced or specialized features.
Once the necessary module is imported into your script, you can make use of the functionality it provides, performing necessary operations against the underlying data source.
Unlike many other data sources, however, Oracle Database provides much more than just a simple means for storing and retrieving restricted amounts of data in a certain format. Thus, it can be used to store, process, and move in and out large volumes of data in different formats in a number of different ways. This means a Python module that bridges Python and Oracle Database is supposed to be fast and reliable, allowing Python coders to make best use of the database functionality.
Figure 1 illustrates this architecture:. If you do not have access to Oracle Database , you can obtain it in one of the following ways:. Probably the simplest way is the first one. If you choose to download and install Oracle Database software in your system, you will need to download and install Oracle SQL Developer separately. Note : If your Python installation is on the same machine as the database, a separate Oracle Instant Client installation is not required, because Oracle Database Client libraries come with an Oracle Database installation.
If your database is remote, you can download and install either the Oracle Instant Client Basic package or its smaller version, the Oracle Instant Client Basic Light package, from the Oracle Instant Client Downloads page , using the Oracle Instant Client packages specific to your system.
This tool will allow you to test a database connection immediately to verify that your Instant Client and network are working correctly. Finally, make sure you download and install Visual Studio Redistributable from Microsoft that matches your Oracle Instant Client's architecture.
For example, Oracle Instant Client If you are on Linux , the simplest way to get and install an Oracle Instant Client package is to download its. Here is what the command looks like:. For Linux distributions that use the. Now that you have installed the Oracle Instant Client libraries, you need to add them to the runtime link path. If Oracle Instant Client is the only Oracle software installed on the machine, update the runtime link path as follows:.
Once you have completed the Oracle Instant Client installation on your system, you can perform the following test to make sure everything works properly:. Note that you can omit the port if it is , because that is the default. Note : The password for the hr sample schema may differ from the one used in the example depicted in the Figure 2.
In this particular example, a connection is being made to the database running within a VM installed from the prebuilt Database App Development VM appliance mentioned earlier in this section. All the passwords in this appliance are initially set to oracle. The next software component to install is Python. Although you most likely already have it on your system, you might want to use a separate installation to follow the examples provided in this series of articles.
You can download the latest version of Python for this series, you will need Python 3 from the Download Python page at Python. For Windows and macOS users, installers are available. You're just one step away from completing the preparation of your working environment. Starting with release 6. See the installation instructions for detailed steps. If you're using another platform, the source package will be downloaded and compiled.
If you have more than one Python installation on your system, you must select the Python executable associated with the Python installation that you want to use.
The table in Figure 3 lists all the wheels available at the time of this writing. For this, you can use the Python interactive shell, an ideal tool when it comes to testing, debugging, evaluating, and so on. To invoke it, just enter the name of the Python executable at a terminal prompt:. If the database instance is in the middle of being started, you may receive an error message. If so, try connecting again in a minute or so. Note : As you will see in the examples later in this series, performing a check to see the version of Oracle Client and Oracle Database being used can be appropriate when you are going to employ a new feature that is not supported by older client or database versions.
Finally, quit the shell using Control-D or using the quit method. This will close the connection for you. In practical terms, this means you can access and manipulate data in an Oracle database from within your Python code, employing a very wide set of features available in Oracle Database. Let's start with a simple script that illustrates how you can issue a query against the database and then print out the retrieved results using only a few lines of code. The query in this particular script is issued against the hr.
Note the use of indentation in the above code. If you are coming from another language, don't forget that indentation in Python is required to indicate what block of code a line belongs to. Be sure that your text editor allows you to see differences between spaces and tabs, because even visually indented lines may not be actually indented from the point of view of Python.
For further details, refer to the documentation. Save the above script to a file called simplequery. Turning back to the script code, note that string Seattle is passed to the query through a bind variable. Using bind variables is recommended, because no additional parsing is required for identical queries the value of a bind variable is supplied at query execution time , which ultimately improves overall performance. DatabaseError exception, raised for errors related to the database, is handled.
Error handling will be covered in more detail in the next part of this series. Upon fetching, data retrieved from the database is implicitly converted to Python data types.
You can see data types mapping in action with the help of the following test. Suppose you want to know how the Oracle Database data types used in the definition of the hr.
Yuli Vasiliev is a software developer, freelance author, and consultant currently specializing in open source development, databases, business intelligence BI , machine learning, and virtualization. Home Menu. View Accounts. Try Oracle Cloud Free Tier. No results found Your search did not match any results. Preparing Your Working Environment The examples provided in this article series were tested with the following software: Oracle Database If you do not have access to Oracle Database , you can obtain it in one of the following ways: Download and install a prebuilt virtual machine VM for Oracle VM VirtualBox containing preconfigured Oracle Database software.
Choose one of the Oracle Database Cloud services that provide access to Oracle Database in the cloud. Deploy Oracle Database as a Docker container, either in the cloud or on premises. If you are a Microsoft Windows user, download the Basic or Basic Light package zip file and then unzip it into a single folder in your system, for example: Copy. Resources for Developers Startups Students and Educators.
Contents Index. With the Oracle dialect, a sequence must always be explicitly specified to enable autoincrement. This is divergent with the majority of documentation examples which assume the usage of an autoincrement-capable database. To specify sequences, use the sqlalchemy. Sequence object which is passed to a Column construct:. New in version 1. SQLAlchemy on the other hand considers an all-lower case identifier name to be case insensitive.
Oracle Database for Python Developers, Part 1: cx_Oracle Quick Start
Released: Dec 3, View statistics for this project via Libraries. Tags Oracle. Dec 3, Oct 1,