0% found this document useful (0 votes)
51 views

Python For The Oracle DBA: A Taste of What's Cooking at US Foods

Python is easy to use for database administrators because it can connect them to various databases, applications, and cloud services. It has clear syntax, dynamic typing, lists and other features that reduce the effort to learn and use. Extensive online documentation and forums provide support. While an initial time investment is required, Python stays approachable during periods away from coding. These traits enable DBAs to build scripts and programs that integrate different systems.

Uploaded by

k2sh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Python For The Oracle DBA: A Taste of What's Cooking at US Foods

Python is easy to use for database administrators because it can connect them to various databases, applications, and cloud services. It has clear syntax, dynamic typing, lists and other features that reduce the effort to learn and use. Extensive online documentation and forums provide support. While an initial time investment is required, Python stays approachable during periods away from coding. These traits enable DBAs to build scripts and programs that integrate different systems.

Uploaded by

k2sh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

A Taste of What’s Cooking at US Foods

Python for the Oracle DBA

Bobby Durrett
Why Python?

• Easy to use
• Connects to everything

2
Easy to use

• Takes effort to learn


• Easy to come back to
• Great online documentation
• Very active online forum
• Features that make it easy to use
• Used for teaching

3
Easy to use - Takes effort to learn

• Python tutorial - https://docs.python.org/3/tutorial/


• edX classes - https://www.edx.org/

• Introduction to Computer Science and Programming Using Python


• 9 weeks, 15 hours per week

• Introduction to Computational Thinking and Data Science


• 10 weeks, 15 hours per week

• Finished second class Dec 22, 2015

4
Easy to use - Easy to come back to

• A language that is easy to use is easy to come back to after not


using it for a while

• Oracle DBAs might go weeks or months without writing new code

• Two other languages that were hard to come back to


– C++
– Java

5
Hello World – C++

#include <iostream>

int main () {
std::cout << "Hello world!" << std::endl;
}

http://rosettacode.org/wiki/Hello_world/Text

6
Hello World – Java

public class HelloWorld


{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}

http://rosettacode.org/wiki/Hello_world/Text

7
Hello World – Python

print("Hello world!")

http://rosettacode.org/wiki/Hello_world/Text

8
Easy to use - Great online documentation

• Google search: python 3 list

• First answer: https://docs.python.org/3/tutorial/datastructures.html

• Two versions of Python: 2 and 3

• Tutorial also

9
Documentation Screenshot

10
Easy to use - Very active online forum

• Stack Overflow - https://stackoverflow.com/

• Structured question and answer format with point system

• Many Python questions

• Fast answers

11
Stack Overflow Screenshot

12
Easy to use - Features that make it easy to use

• Dynamic Typing

• Lists

• Indentation

13
Dynamic typing
>>> x=5
>>>
>>> type(x)
<class 'int'>
>>>
>>> x="Hello"
>>>
>>> type(x)
<class 'str'>
>>>
>>> x = [1,2,"Greetings"]
>>>
>>> type(x)
<class 'list'>

14
List type

>>> l=[1,2,3]
>>>
>>> l.append(4)
>>>
>>> l
[1, 2, 3, 4]
>>>
>>> l[2:4]
[3, 4]
>>>
>>> l[3]
4

15
Indentation
>>> x = 5
>>> if x > 0:
... print("Greater than zero")
... x = 0
...
Greater than zero
>>>
>>> if x == 0:
... print("Equals zero")
... x = 1
File "<stdin>", line 3
x = 1
^
IndentationError: unindent does not match any outer
indentation level

16
Easy to use – used for teaching

• Python books for children


• Raspberry Pi
• MIT
• University of Arizona

17
Connects to everything

• Databases
• Graphics
• Local programs
• Remote servers
• Cloud

What is Python? Executive Summary:

“…use as a scripting or glue language to connect existing


components together..”

https://www.python.org/doc/essays/blurb/

18
Connects to everything - Databases

• Oracle
• Snowflake
• MySQL
• Google BigQuery

19
Oracle Database
import cx_Oracle

con = cx_Oracle.connect('test/test@dbatest')

cur = con.cursor()

cur.execute('select table_name from user_tables')

for result in cur:


print(result[0])

cur.close()
con.close()
20
Connects to everything - Graphics

• Matplotlib
• http://matplotlib.org/index.html

• PythonDBAGraphs
• https://github.com/bobbydurrett/PythonDBAGraphs

21
PythonDBAGraphs example

22
Connects to everything – local programs

• Subprocess module

• https://docs.python.org/3/library/subprocess.html

p = subprocess.Popen(['sqlplus','/nolog'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

23
Connects to everything – remote servers

• Ftplib - ftp

• https://docs.python.org/3/library/ftplib.html

• Paramiko – ssh

• http://www.paramiko.org/

24
Connects to everything - Cloud

import boto3
import botocore

s3 = boto3.resource('s3’)

mybucket='aws.xyz.bobby’

bucket = s3.Bucket(mybucket)

s3.meta.client.head_bucket(Bucket=mybucket)

s3.Object(mybucket,'Test/test3.csv’).put(
Body=open('test3.csv', 'rb'))

25
Conclusion

• One DBA’s experience


• Why I think Python is useful to me:
– Easy to use
– Connects to everything
• Does Python make sense in your situation?

26
Contact Information

• Name: Bobby Durrett


• Email: [email protected]
• Blog: http://www.bobbydurrettdba.com/

27

You might also like