SlideShare a Scribd company logo
Database interfaces
  beheshtraya@gmail.com
Generic Database Interfaces
         and APIs
• ODBC Support
   o pyodbc
   o mxODBC


• ADO Support
   o adodbapi


• JDBC Support
   o Integrated in Jython




Python database interfaces   Fall 2012
pyodbc
• Connect to a Database
     Make a direct connection to a database and
     create a cursor.


   import pyodbc
   cnxn = pyodbc.connect('DRIVER={SQL Server};
                         SERVER=localhost;
                         DATABASE=testdb;
                         UID=user;
                         PWD=pass')
   cursor = cnxn.cursor()



Python database interfaces                       Fall 2012
pyodbc
• Selecting Some Data
      Execute query then fetch results.

cursor.execute("select user_id, user_name from users")
row = cursor.fetchone()
print 'name:', row[1]        # access by column index
print 'name:', row.user_name # or access by name


cursor.execute("select user_id, user_name from users")
rows = cursor.fetchall()
for row in rows:
  print row.user_id, row.user_name


 Python database interfaces                              Fall 2012
pyodbc
• Inserting or deleting
      Execute query then commit changes.


cursor.execute("insert into products(id, name) values ('pyodbc',
'awesome')")
cnxn.commit()



deleted = cursor.execute("delete from products where id <> 'pyodbc'").r
cnxn.commit()




  Python database interfaces                                 Fall 2012
Interfaces for Relational
             Database Systems

• General Purpose Database Systems

• Database Systems for Embedding Into
  Applications




Python database interfaces              Fall 2012
General Purpose Database
                  Systems
•     Microsoft SQL Server
•     Oracle
•     MySQL
•     IBM DB2
•     PostgreSQL
•     Firebird (and Interbase)
•     Informix
•     SAP DB (also known as "MaxDB")
•     …

    Python database interfaces         Fall 2012
• mssql
   o MS SQL Server module for Python




• pymssql
   o A fast MS SQL server client library for Python directly using C API
     instead of ODBC.




Python database interfaces                                         Fall 2012
• cx_Oracle
   o Lite Oracle DB Server module for Python




• DCOracle2
   o    Advanced Python DB API 2.0 adapter for Oracle from
       Zope company.




Python database interfaces                                   Fall 2012
• MySQLdb
   o The most famous library for connecting MySQL
     in python.



• PyMySQL
   o    Pure-Python MySQL client library.




Python database interfaces                          Fall 2012
MySQLdb
• Benefits:
   o    Very fast and optimized ( written in C)
   o    Has big community
   o    Defense SQL injection
   o    very efficient



   import MySQLdb
   conn = mysql.connect(‘localhost’, ‘username’, ‘password’, ‘db name’)
   cursor = conn.cursor()
   cursor.execute(‚Example query‛)
   cursor.commit()    #needed for insert and delete




 Python database interfaces                                        Fall 2012
• Ibm_db
   o Python support for IBM DB2 and IBM Informix



• PyDB2
   o    Pure-Python DB2 interface library.




Python database interfaces                         Fall 2012
• Psycopg
   o The most popular PostgreSQL adapter for the Python




• PyGreSQL
   o Open-source Python module that interfaces to
     a PostgreSQL database




Python database interfaces                                Fall 2012
Interfaces for Non-Relational
            Database Systems

•     MetaKit
•     ZODB
•     Berkeley DB
•     Durus
•     Atop




    Python database interfaces   Fall 2012
Native Python Databases
• Buzhug
   o buzhug is a fast, portable, pure-Python database engine, using a
     pythonic non-SQL syntax for all operations.



• SnakeSQL
   o SnakeSQL is a pure Python SQL database written to remove
     the dependence of the Python Web Modules on 3rd party
     drivers for non-Python databases.




Python database interfaces                                    Fall 2012
Django is a high-level Python Web
    framework that encourages rapid
   development and clean, pragmatic
                  design.



Python database interfaces         Fall 2012
Set database server

DATABASES = {
  'default': {
     'ENGINE': 'django.db.backends.’  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3'
or 'oracle'.
     'NAME': 'main_db.db',            # Or path to database file if using sqlite3.
     'USER': '',
     'PASSWORD': '',
     'HOST': '',           # Set to empty string for localhost.
     'PORT': '',           # Set to empty string for default.
  }
}




 Python database interfaces                                                   Fall 2012
Using multiple database
•     DATABASES = {
        'default': {
              'NAME': 'app_data',
              'ENGINE': 'django.db.backends.postgresql_psycopg2',
              'USER': 'postgres_user',
              'PASSWORD': 's3krit' },
        'users': {
              'NAME': 'user_data',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te' }
}




    Python database interfaces                                      Fall 2012
Resources

• Expert Python
  Programming




Python database interfaces               Fall 2012
Resources

• wiki.python.org



• www.djangoproject.com




Python database interfaces               Fall 2012
Python database interfaces   Fall 2012

More Related Content

What's hot (20)

12 SQL
12 SQL12 SQL
12 SQL
Praveen M Jigajinni
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
mohamedsaad24
 
MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
Compare Infobase Limited
 
Origins and evolution of HTML and XHTML
Origins and evolution of HTML and XHTMLOrigins and evolution of HTML and XHTML
Origins and evolution of HTML and XHTML
Howpk
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
hendersk
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
Reem Alattas
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Sql - Structured Query Language
Sql - Structured Query LanguageSql - Structured Query Language
Sql - Structured Query Language
Wan Hussain Wan Ishak
 
Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
Mark Rees
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
Sourabh Sahu
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
mcantelon
 
Origins and evolution of HTML and XHTML
Origins and evolution of HTML and XHTMLOrigins and evolution of HTML and XHTML
Origins and evolution of HTML and XHTML
Howpk
 
Method Handles in Java
Method Handles in JavaMethod Handles in Java
Method Handles in Java
hendersk
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
Reem Alattas
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
Shrija Madhu
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
Mark Rees
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
mcantelon
 

Viewers also liked (20)

Information is Everything: Marketing in the Age of Disruption
Information is Everything: Marketing in the Age of DisruptionInformation is Everything: Marketing in the Age of Disruption
Information is Everything: Marketing in the Age of Disruption
Tahzoo
 
Untitled presentation (1)
Untitled presentation (1)Untitled presentation (1)
Untitled presentation (1)
Simo Lensment
 
Seventies Swagger
Seventies SwaggerSeventies Swagger
Seventies Swagger
LIM College
 
Educamers - education and gamers
Educamers - education and gamersEducamers - education and gamers
Educamers - education and gamers
CROWDERRY
 
Fashion of China Andrew Charette
Fashion of China Andrew CharetteFashion of China Andrew Charette
Fashion of China Andrew Charette
LIM College
 
Understanding social media
Understanding social mediaUnderstanding social media
Understanding social media
Sara Carbaugh
 
IED - Progettazione 3 - SoyJoy
IED - Progettazione 3 - SoyJoyIED - Progettazione 3 - SoyJoy
IED - Progettazione 3 - SoyJoy
Francesco Cardarelli
 
Our thought is our life
Our thought is our lifeOur thought is our life
Our thought is our life
kmbehzad
 
Prosumerism
ProsumerismProsumerism
Prosumerism
CROWDERRY
 
LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012
CROWDERRY
 
IED - Progettazione 4 - AgosDucati, un mondo unico
IED - Progettazione 4 - AgosDucati, un mondo unicoIED - Progettazione 4 - AgosDucati, un mondo unico
IED - Progettazione 4 - AgosDucati, un mondo unico
Francesco Cardarelli
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
Chaasadyah
 
China presentation
China presentationChina presentation
China presentation
tdematties
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
Chaasadyah
 
Cipa nº 5
Cipa nº 5Cipa nº 5
Cipa nº 5
pedagogia2012melgar
 
Camp tech
Camp techCamp tech
Camp tech
npolk
 
Dutch Spices UK
Dutch Spices UKDutch Spices UK
Dutch Spices UK
dutchspices
 
Qr qrazy
Qr qrazyQr qrazy
Qr qrazy
npolk
 
Искусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсингеИскусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсинге
CROWDERRY
 
Handelspresentatie dutch spices engels
Handelspresentatie dutch spices engelsHandelspresentatie dutch spices engels
Handelspresentatie dutch spices engels
dutchspices
 
Information is Everything: Marketing in the Age of Disruption
Information is Everything: Marketing in the Age of DisruptionInformation is Everything: Marketing in the Age of Disruption
Information is Everything: Marketing in the Age of Disruption
Tahzoo
 
Untitled presentation (1)
Untitled presentation (1)Untitled presentation (1)
Untitled presentation (1)
Simo Lensment
 
Seventies Swagger
Seventies SwaggerSeventies Swagger
Seventies Swagger
LIM College
 
Educamers - education and gamers
Educamers - education and gamersEducamers - education and gamers
Educamers - education and gamers
CROWDERRY
 
Fashion of China Andrew Charette
Fashion of China Andrew CharetteFashion of China Andrew Charette
Fashion of China Andrew Charette
LIM College
 
Understanding social media
Understanding social mediaUnderstanding social media
Understanding social media
Sara Carbaugh
 
Our thought is our life
Our thought is our lifeOur thought is our life
Our thought is our life
kmbehzad
 
LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012
CROWDERRY
 
IED - Progettazione 4 - AgosDucati, un mondo unico
IED - Progettazione 4 - AgosDucati, un mondo unicoIED - Progettazione 4 - AgosDucati, un mondo unico
IED - Progettazione 4 - AgosDucati, un mondo unico
Francesco Cardarelli
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
Chaasadyah
 
China presentation
China presentationChina presentation
China presentation
tdematties
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
Chaasadyah
 
Camp tech
Camp techCamp tech
Camp tech
npolk
 
Qr qrazy
Qr qrazyQr qrazy
Qr qrazy
npolk
 
Искусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсингеИскусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсинге
CROWDERRY
 
Handelspresentatie dutch spices engels
Handelspresentatie dutch spices engelsHandelspresentatie dutch spices engels
Handelspresentatie dutch spices engels
dutchspices
 
Ad

Similar to Python database interfaces (20)

Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
Mark Rees
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
Chapter 6 Interface Python with MYSQL.pptx
Chapter 6 Interface Python with MYSQL.pptxChapter 6 Interface Python with MYSQL.pptx
Chapter 6 Interface Python with MYSQL.pptx
sarofba
 
Class 12 CS Ch-16 MySQL PPT.pptx
Class 12 CS Ch-16 MySQL PPT.pptxClass 12 CS Ch-16 MySQL PPT.pptx
Class 12 CS Ch-16 MySQL PPT.pptx
DeepaG66
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
AkramWaseem
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
unit-5 SQL 1 creating a databse connection.pptx
unit-5 SQL 1 creating a databse connection.pptxunit-5 SQL 1 creating a databse connection.pptx
unit-5 SQL 1 creating a databse connection.pptx
HuzaifaAhmedFarooqi
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
HiteshNandi
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
Fulvio Corno
 
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGREDATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
Interface python with sql database.pdf--
Interface python with sql database.pdf--Interface python with sql database.pdf--
Interface python with sql database.pdf--
jagaspeed09
 
Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
MohammadImran709594
 
Database Connectivity using Python and MySQL
Database Connectivity using Python and MySQLDatabase Connectivity using Python and MySQL
Database Connectivity using Python and MySQL
devsuchaye
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
Survey Department
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
AkramWaseem
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/Python
Jesper Wisborg Krogh
 
Chapter -7.pptx
Chapter -7.pptxChapter -7.pptx
Chapter -7.pptx
MikialeTesfamariam
 
Database programming
Database programmingDatabase programming
Database programming
Shree M.L.Kakadiya MCA mahila college, Amreli
 
python db connection samples and program
python db connection samples and programpython db connection samples and program
python db connection samples and program
usha raj
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
Mark Rees
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
Chapter 6 Interface Python with MYSQL.pptx
Chapter 6 Interface Python with MYSQL.pptxChapter 6 Interface Python with MYSQL.pptx
Chapter 6 Interface Python with MYSQL.pptx
sarofba
 
Class 12 CS Ch-16 MySQL PPT.pptx
Class 12 CS Ch-16 MySQL PPT.pptxClass 12 CS Ch-16 MySQL PPT.pptx
Class 12 CS Ch-16 MySQL PPT.pptx
DeepaG66
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
AkramWaseem
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
Frederic Descamps
 
unit-5 SQL 1 creating a databse connection.pptx
unit-5 SQL 1 creating a databse connection.pptxunit-5 SQL 1 creating a databse connection.pptx
unit-5 SQL 1 creating a databse connection.pptx
HuzaifaAhmedFarooqi
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
HiteshNandi
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
Fulvio Corno
 
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGREDATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
DATABASE CONNECTIVITY PYTHON USING MYSQL/SQLITE/POSTGRE
deepalishinkar1
 
Interface python with sql database.pdf--
Interface python with sql database.pdf--Interface python with sql database.pdf--
Interface python with sql database.pdf--
jagaspeed09
 
Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
MohammadImran709594
 
Database Connectivity using Python and MySQL
Database Connectivity using Python and MySQLDatabase Connectivity using Python and MySQL
Database Connectivity using Python and MySQL
devsuchaye
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
Survey Department
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
AkramWaseem
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/Python
Jesper Wisborg Krogh
 
python db connection samples and program
python db connection samples and programpython db connection samples and program
python db connection samples and program
usha raj
 
Ad

Recently uploaded (20)

MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 

Python database interfaces

  • 2. Generic Database Interfaces and APIs • ODBC Support o pyodbc o mxODBC • ADO Support o adodbapi • JDBC Support o Integrated in Jython Python database interfaces Fall 2012
  • 3. pyodbc • Connect to a Database Make a direct connection to a database and create a cursor. import pyodbc cnxn = pyodbc.connect('DRIVER={SQL Server}; SERVER=localhost; DATABASE=testdb; UID=user; PWD=pass') cursor = cnxn.cursor() Python database interfaces Fall 2012
  • 4. pyodbc • Selecting Some Data Execute query then fetch results. cursor.execute("select user_id, user_name from users") row = cursor.fetchone() print 'name:', row[1] # access by column index print 'name:', row.user_name # or access by name cursor.execute("select user_id, user_name from users") rows = cursor.fetchall() for row in rows: print row.user_id, row.user_name Python database interfaces Fall 2012
  • 5. pyodbc • Inserting or deleting Execute query then commit changes. cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome')") cnxn.commit() deleted = cursor.execute("delete from products where id <> 'pyodbc'").r cnxn.commit() Python database interfaces Fall 2012
  • 6. Interfaces for Relational Database Systems • General Purpose Database Systems • Database Systems for Embedding Into Applications Python database interfaces Fall 2012
  • 7. General Purpose Database Systems • Microsoft SQL Server • Oracle • MySQL • IBM DB2 • PostgreSQL • Firebird (and Interbase) • Informix • SAP DB (also known as "MaxDB") • … Python database interfaces Fall 2012
  • 8. • mssql o MS SQL Server module for Python • pymssql o A fast MS SQL server client library for Python directly using C API instead of ODBC. Python database interfaces Fall 2012
  • 9. • cx_Oracle o Lite Oracle DB Server module for Python • DCOracle2 o Advanced Python DB API 2.0 adapter for Oracle from Zope company. Python database interfaces Fall 2012
  • 10. • MySQLdb o The most famous library for connecting MySQL in python. • PyMySQL o Pure-Python MySQL client library. Python database interfaces Fall 2012
  • 11. MySQLdb • Benefits: o Very fast and optimized ( written in C) o Has big community o Defense SQL injection o very efficient import MySQLdb conn = mysql.connect(‘localhost’, ‘username’, ‘password’, ‘db name’) cursor = conn.cursor() cursor.execute(‚Example query‛) cursor.commit() #needed for insert and delete Python database interfaces Fall 2012
  • 12. • Ibm_db o Python support for IBM DB2 and IBM Informix • PyDB2 o Pure-Python DB2 interface library. Python database interfaces Fall 2012
  • 13. • Psycopg o The most popular PostgreSQL adapter for the Python • PyGreSQL o Open-source Python module that interfaces to a PostgreSQL database Python database interfaces Fall 2012
  • 14. Interfaces for Non-Relational Database Systems • MetaKit • ZODB • Berkeley DB • Durus • Atop Python database interfaces Fall 2012
  • 15. Native Python Databases • Buzhug o buzhug is a fast, portable, pure-Python database engine, using a pythonic non-SQL syntax for all operations. • SnakeSQL o SnakeSQL is a pure Python SQL database written to remove the dependence of the Python Web Modules on 3rd party drivers for non-Python databases. Python database interfaces Fall 2012
  • 16. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Python database interfaces Fall 2012
  • 17. Set database server DATABASES = { 'default': { 'ENGINE': 'django.db.backends.’ # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'main_db.db', # Or path to database file if using sqlite3. 'USER': '', 'PASSWORD': '', 'HOST': '', # Set to empty string for localhost. 'PORT': '', # Set to empty string for default. } } Python database interfaces Fall 2012
  • 18. Using multiple database • DATABASES = { 'default': { 'NAME': 'app_data', 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, 'users': { 'NAME': 'user_data', 'ENGINE': 'django.db.backends.mysql', 'USER': 'mysql_user', 'PASSWORD': 'priv4te' } } Python database interfaces Fall 2012
  • 19. Resources • Expert Python Programming Python database interfaces Fall 2012