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)

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Function overloading
Function overloadingFunction overloading
Function overloading
Selvin Josy Bai Somu
 
Operators in python
Operators in pythonOperators in python
Operators in python
deepalishinkar1
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
python Function
python Function python Function
python Function
Ronak Rathi
 
Introduction to OOP in Python
Introduction to OOP in PythonIntroduction to OOP in Python
Introduction to OOP in Python
Aleksander Fabijan
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
Binay Kumar Ray
 
20.3 Java encapsulation
20.3 Java encapsulation20.3 Java encapsulation
20.3 Java encapsulation
Intro C# Book
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Ternary operator
Ternary operatorTernary operator
Ternary operator
Hitesh Kumar
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
Mayank Jain
 
Constructors in C++
Constructors in C++Constructors in C++
Constructors in C++
RubaNagarajan
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
Lalitkumar_98
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Python-DataAbstarction.pptx
Python-DataAbstarction.pptxPython-DataAbstarction.pptx
Python-DataAbstarction.pptx
Karudaiyar Ganapathy
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
Sets in python
Sets in pythonSets in python
Sets in python
baabtra.com - No. 1 supplier of quality freshers
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 

Viewers also liked (20)

Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
Mark Rees
 
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
 
Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
Mark Rees
 
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
 
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)

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
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
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
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
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
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
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
 
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
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
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
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
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
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
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
 
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
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 

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