Skip to content

Commit 4472770

Browse files
Updated the Jupyter notebook samples to cover recently added features.
1 parent 2df11c5 commit 4472770

File tree

13 files changed

+823
-210
lines changed

13 files changed

+823
-210
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Common Changes
3737
#) Fixed bug that caused ``ORA-03137: malformed TTC packet from client
3838
rejected`` exception to be raised when attempting to call
3939
:meth:`Cursor.parse()` on a scrollable cursor.
40+
#) Updated the `Jupyter notebook samples <https://github.com/oracle/
41+
python-oracledb/tree/main/samples/notebooks>`__ to cover recent
42+
python-oracledb features.
4043

4144

4245
oracledb `3.4.0 <https://github.com/oracle/python-oracledb/compare/v3.3.0...v3.4.0>`__ (October 2025)

samples/notebooks/1-Connection.ipynb

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"Install with a command like one of the following:\n",
5858
"\n",
5959
"```\n",
60-
"$ python3 -m pip install oracledb --upgrade\n",
61-
"$ python3 -m pip install oracledb --upgrade --user\n",
62-
"$ python3 -m pip install oracledb --upgrade --user --proxy=http://proxy.example.com:80\n",
60+
"$ python -m pip install oracledb --upgrade\n",
61+
"$ python -m pip install oracledb --upgrade --user\n",
62+
"$ python -m pip install oracledb --upgrade --user --proxy=http://proxy.example.com:80\n",
6363
"```"
6464
]
6565
},
@@ -105,7 +105,7 @@
105105
"cell_type": "markdown",
106106
"metadata": {},
107107
"source": [
108-
"Instead of hard coding the password, you could prompt for a value, pass it as an environment variable, or use Oracle \"external authentication\"."
108+
"Instead of hard coding the password in your applications, you could prompt for a value, pass it as an environment variable, or use Oracle \"external authentication\"."
109109
]
110110
},
111111
{
@@ -133,13 +133,13 @@
133133
"cell_type": "markdown",
134134
"metadata": {},
135135
"source": [
136-
"Oracle Client 19c improved [Easy Connect Plus](https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-8C85D289-6AF3-41BC-848B-BF39D32648BA) syntax with additional optional settings, for example:\n",
136+
"Oracle's [Easy Connect](https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-8C85D289-6AF3-41BC-848B-BF39D32648BA) syntax allows many optional settings, for example:\n",
137137
"\n",
138138
"```\n",
139139
"cs = \"tcps://my.cloud.com:1522/orclpdb1?connect_timeout=4&expire_time=10\"\n",
140140
"```\n",
141141
"\n",
142-
"<!-- See the [technical brief](https://download.oracle.com/ocomdocs/global/Oracle-Net-19c-Easy-Connect-Plus.pdf). -->"
142+
"See the Oracle Database Easy Connect [technical brief](https://download.oracle.com/ocomdocs/global/Oracle-Net-Easy-Connect-Plus.pdf) for other options."
143143
]
144144
},
145145
{
@@ -148,7 +148,7 @@
148148
"source": [
149149
"### Oracle Network and Oracle Client Configuration Files\n",
150150
"\n",
151-
"Oracle Database's `tnsnames.ora` file can be used. This file maps a connect descriptor to an alias. \n",
151+
"Instead of the Easy Connect syntax, a TNS Alias from a `tnsnames.ora` file can be used. This file maps connect descriptors to TNS aliases. \n",
152152
"\n",
153153
"Documentation reference link: [Optional configuration files](https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#optional-oracle-net-configuration-files)"
154154
]
@@ -159,7 +159,7 @@
159159
"source": [
160160
"\n",
161161
"# tnsnames.ora in /opt/oracle/configdir\n",
162-
" \n",
162+
"\n",
163163
"highperfdb = (description= \n",
164164
" (retry_count=5)(retry_delay=3)\n",
165165
" (address=(protocol=tcps)(port=1522)(host=xxxxxx.oraclecloud.com))\n",
@@ -173,7 +173,7 @@
173173
"cell_type": "markdown",
174174
"metadata": {},
175175
"source": [
176-
"Your Python code could use the alias as the connection `dsn` value:\n",
176+
"Your Python code could use the TNS Alias as the connection `dsn` value:\n",
177177
"```\n",
178178
"connection = oracledb.connect(user=un, password=pw, dsn=\"highperfdb\", config_dir=\"/opt/oracle/configdir\")\n",
179179
"```"
@@ -192,7 +192,7 @@
192192
"source": [
193193
"### Standalone Connections\n",
194194
"\n",
195-
"Standalone connections are simple to create."
195+
"Standalone connections are simple to create. They are suitable for single-user applications that do not run very long."
196196
]
197197
},
198198
{
@@ -208,7 +208,7 @@
208208
"metadata": {},
209209
"outputs": [],
210210
"source": [
211-
"# Stand-alone Connections\n",
211+
"# Stand-alone Connection\n",
212212
"\n",
213213
"connection = oracledb.connect(user=un, password=pw, dsn=cs)\n",
214214
"\n",
@@ -227,10 +227,12 @@
227227
"metadata": {},
228228
"source": [
229229
"#### Pools are highly recommended if you have:\n",
230-
"- a lot of connections that will be used for short periods of time\n",
231-
"- or a small number of connections that are idle for long periods of time\n",
230+
"- A lot of connections that will be used for short periods of time\n",
231+
"- Or a small number of connections that are idle for long periods of time\n",
232232
"\n",
233233
"#### Pool advantages\n",
234+
"Try to architect your applications to use connection pools to take advantage of:\n",
235+
"\n",
234236
"- Reduced cost of setting up and tearing down connections\n",
235237
"- Dead connection detection and automatic re-establishment"
236238
]
@@ -278,17 +280,19 @@
278280
"cell_type": "markdown",
279281
"metadata": {},
280282
"source": [
281-
"Close connections when not needed. This is important for pooled connections.\n",
283+
"Close connections when not needed. This is important for pooled connections. With a connection pool, closing the connection releases it back to the pool for later reuse.\n",
284+
"\n",
285+
"To avoid resource closing order issues, you should use `with` or let resources be closed at end of scope:\n",
282286
"\n",
283287
"```\n",
284-
"connection.close()\n",
288+
"with pool.acquire() as connection:\n",
289+
" do_something(connection)\n",
285290
"```\n",
286291
"\n",
287-
"To avoid resource closing order issues, you may want to use `with` or let resources be closed at end of scope:\n",
292+
"Or you can explicitly close connections:\n",
288293
"\n",
289294
"```\n",
290-
"with pool.acquire() as connection:\n",
291-
" do_something(connection)\n",
295+
"connection.close()\n",
292296
"```"
293297
]
294298
},
@@ -333,8 +337,9 @@
333337
"cell_type": "markdown",
334338
"metadata": {},
335339
"source": [
336-
"#### Memory example with 5000 application users and a DRCP pool of size 100\n",
337-
"![DRCP memory comparison](images/drcp-comparison.png)"
340+
"#### Database memory usage example with 5000 application users and a DRCP pool of size 100\n",
341+
"![DRCP memory comparison](images/drcp-comparison.png)\n",
342+
"The numbers are examples."
338343
]
339344
},
340345
{
@@ -375,7 +380,7 @@
375380
"name": "python",
376381
"nbconvert_exporter": "python",
377382
"pygments_lexer": "ipython3",
378-
"version": "3.9.6"
383+
"version": "3.9.24"
379384
}
380385
},
381386
"nbformat": 4,

samples/notebooks/2-Queries.ipynb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
]
1616
},
1717
{
18-
"cell_type": "code",
19-
"execution_count": null,
18+
"cell_type": "markdown",
2019
"metadata": {},
21-
"outputs": [],
2220
"source": [
23-
"import oracledb"
21+
"Setup for this notebook:"
2422
]
2523
},
2624
{
@@ -29,6 +27,8 @@
2927
"metadata": {},
3028
"outputs": [],
3129
"source": [
30+
"import oracledb\n",
31+
"\n",
3232
"un = \"pythondemo\"\n",
3333
"pw = \"welcome\"\n",
3434
"\n",
@@ -104,7 +104,25 @@
104104
" for r in rows:\n",
105105
" print(r)\n",
106106
" if len(rows) < cursor.arraysize:\n",
107-
" break\n"
107+
" break"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {},
113+
"source": [
114+
"A common idiom to use an iterator and process each row individually. Internally python-oracledb will fetch from the database in batches controlled by tuning parameters shown in the next section:"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"with connection.cursor() as cursor:\n",
124+
" for row in cursor.execute(\"select * from SampleQueryTab\"):\n",
125+
" print(row)"
108126
]
109127
},
110128
{
@@ -519,7 +537,7 @@
519537
"name": "python",
520538
"nbconvert_exporter": "python",
521539
"pygments_lexer": "ipython3",
522-
"version": "3.9.6"
540+
"version": "3.9.24"
523541
}
524542
},
525543
"nbformat": 4,

0 commit comments

Comments
 (0)