SlideShare a Scribd company logo
1 of 21
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)

Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
embedded-static-&dynamic
embedded-static-&dynamicembedded-static-&dynamic
embedded-static-&dynamic
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modelling
 
MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Er model
Er modelEr model
Er model
 
C# operators
C# operatorsC# operators
C# operators
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Pandas Series
Pandas SeriesPandas Series
Pandas Series
 
SQL
SQLSQL
SQL
 
Generalization and specialization
Generalization and specializationGeneralization and specialization
Generalization and specialization
 

Viewers also liked

Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with PythonMark 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 DisruptionTahzoo
 
Untitled presentation (1)
Untitled presentation (1)Untitled presentation (1)
Untitled presentation (1)Simo Lensment
 
Seventies Swagger
Seventies SwaggerSeventies Swagger
Seventies SwaggerLIM College
 
Educamers - education and gamers
Educamers - education and gamersEducamers - education and gamers
Educamers - education and gamersCROWDERRY
 
Fashion of China Andrew Charette
Fashion of China Andrew CharetteFashion of China Andrew Charette
Fashion of China Andrew CharetteLIM College
 
Understanding social media
Understanding social mediaUnderstanding social media
Understanding social mediaSara Carbaugh
 
Our thought is our life
Our thought is our lifeOur thought is our life
Our thought is our lifekmbehzad
 
LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012CROWDERRY
 
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 unicoFrancesco Cardarelli
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around usChaasadyah
 
China presentation
China presentationChina presentation
China presentationtdematties
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around usChaasadyah
 
Camp tech
Camp techCamp tech
Camp technpolk
 
Qr qrazy
Qr qrazyQr qrazy
Qr qrazynpolk
 
Искусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсингеИскусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсингеCROWDERRY
 

Viewers also liked (20)

Relational Database Access with Python
Relational Database Access with PythonRelational Database Access with Python
Relational Database Access with Python
 
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
 
Untitled presentation (1)
Untitled presentation (1)Untitled presentation (1)
Untitled presentation (1)
 
Seventies Swagger
Seventies SwaggerSeventies Swagger
Seventies Swagger
 
Educamers - education and gamers
Educamers - education and gamersEducamers - education and gamers
Educamers - education and gamers
 
Fashion of China Andrew Charette
Fashion of China Andrew CharetteFashion of China Andrew Charette
Fashion of China Andrew Charette
 
Understanding social media
Understanding social mediaUnderstanding social media
Understanding social media
 
IED - Progettazione 3 - SoyJoy
IED - Progettazione 3 - SoyJoyIED - Progettazione 3 - SoyJoy
IED - Progettazione 3 - SoyJoy
 
Our thought is our life
Our thought is our lifeOur thought is our life
Our thought is our life
 
Prosumerism
ProsumerismProsumerism
Prosumerism
 
LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012LEVELAPPME Summer School Report 2012
LEVELAPPME Summer School Report 2012
 
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
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
 
China presentation
China presentationChina presentation
China presentation
 
Colors are all around us
Colors are all around usColors are all around us
Colors are all around us
 
Cipa nº 5
Cipa nº 5Cipa nº 5
Cipa nº 5
 
Camp tech
Camp techCamp tech
Camp tech
 
Dutch Spices UK
Dutch Spices UKDutch Spices UK
Dutch Spices UK
 
Qr qrazy
Qr qrazyQr qrazy
Qr qrazy
 
Искусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсингеИскусственный интеллект в краудсорсинге
Искусственный интеллект в краудсорсинге
 

Similar to Python database interfaces

Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdfMohammadImran709594
 
Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMCIcinga
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBXESUG
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdfHiteshNandi
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
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
 
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 1AkramWaseem
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1Ivan Ma
 
Composable Parallel Processing in Apache Spark and Weld
Composable Parallel Processing in Apache Spark and WeldComposable Parallel Processing in Apache Spark and Weld
Composable Parallel Processing in Apache Spark and WeldDatabricks
 
The Nitty Gritty of Advanced Analytics Using Apache Spark in Python
The Nitty Gritty of Advanced Analytics Using Apache Spark in PythonThe Nitty Gritty of Advanced Analytics Using Apache Spark in Python
The Nitty Gritty of Advanced Analytics Using Apache Spark in PythonMiklos Christine
 
Introduction to Foxx by our community member Iskandar Soesman @ikandars
Introduction to Foxx by our community member Iskandar Soesman @ikandarsIntroduction to Foxx by our community member Iskandar Soesman @ikandars
Introduction to Foxx by our community member Iskandar Soesman @ikandarsArangoDB Database
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and KubernetesMongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and KubernetesMongoDB
 
Java database programming with jdbc
Java database programming with jdbcJava database programming with jdbc
Java database programming with jdbcsriram raj
 
A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...MongoDB
 
Jump Start on Apache Spark 2.2 with Databricks
Jump Start on Apache Spark 2.2 with DatabricksJump Start on Apache Spark 2.2 with Databricks
Jump Start on Apache Spark 2.2 with DatabricksAnyscale
 
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me AnythingDenodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me AnythingDenodo
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 

Similar to Python database interfaces (20)

Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
 
Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMC
 
Squeak DBX
Squeak DBXSqueak DBX
Squeak DBX
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
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
 
PI-RDBMS.ppt
PI-RDBMS.pptPI-RDBMS.ppt
PI-RDBMS.ppt
 
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
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1
 
Composable Parallel Processing in Apache Spark and Weld
Composable Parallel Processing in Apache Spark and WeldComposable Parallel Processing in Apache Spark and Weld
Composable Parallel Processing in Apache Spark and Weld
 
The Nitty Gritty of Advanced Analytics Using Apache Spark in Python
The Nitty Gritty of Advanced Analytics Using Apache Spark in PythonThe Nitty Gritty of Advanced Analytics Using Apache Spark in Python
The Nitty Gritty of Advanced Analytics Using Apache Spark in Python
 
Introduction to Foxx by our community member Iskandar Soesman @ikandars
Introduction to Foxx by our community member Iskandar Soesman @ikandarsIntroduction to Foxx by our community member Iskandar Soesman @ikandars
Introduction to Foxx by our community member Iskandar Soesman @ikandars
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and KubernetesMongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
 
Java database programming with jdbc
Java database programming with jdbcJava database programming with jdbc
Java database programming with jdbc
 
A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...A flexible plugin like data layer - decouple your -_application logic from yo...
A flexible plugin like data layer - decouple your -_application logic from yo...
 
Jump Start on Apache Spark 2.2 with Databricks
Jump Start on Apache Spark 2.2 with DatabricksJump Start on Apache Spark 2.2 with Databricks
Jump Start on Apache Spark 2.2 with Databricks
 
Denodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me AnythingDenodo Partner Connect: Technical Webinar - Ask Me Anything
Denodo Partner Connect: Technical Webinar - Ask Me Anything
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 

Recently uploaded

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Python database interfaces

  • 1. Database interfaces beheshtraya@gmail.com
  • 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