I am trying to build a tool that one step of it is connecting to MySQL database.
Just I am so confused about ODBC. If I want to build a cross platform connector by python, should I use python connector or ODBC connector?
I know JDBC, but ODBC stands for Open Database Connectivity. It looks like more compatible.
Could anyone help me clarify that? Thank you very much.
Python has its own DB API v2.0 abstraction layer to connect to databases (it serves the same purpose of ODBC or JDBC but for Python). You should use one of the DB API v2.0 compliant oursql, MySQLdb or PyMySQL packages to connect to MySQL from Python. All these packages are cross platform and will work on Linux, Windows and MacOS X. oursql, and MySQLdb are wrappers for libmysql and PyMySQL is a pure Python implementation.
Note that there are DB API v2.0 implementations (like pyodbc) that provide ODBC connectivity, so conceptually you could connect to MySQL via ODBC, but this would have inferior performance than the above mentioned "native" drivers because of the extra abstraction layers.
Related
So I am doing a assignment which is to connect to a database and do operations on it. For that I have chosen sqlite3 and for connecting to the database I found the ODBC driver for python is pyodbc.
My questions are, what is the difference between using pyodbc and doing it using the library sqlite3, i.e., import sqlite3 ? And is the pyodbc driver integrated in sqlite3?
pyodbc is an API that allows you to interact with any database that provides provides a odbc driver for it's database. If you use the SQLite library directly and one day want to switch to another database, you will have to revise your code to either use pyodbc or the database specific API for the database you are migrating to.
You can alternatively connect to SQLite using pyodbc by using the SQLite pyodbc driver. See response here: Connect to SQLite3 server using PyODBC, Python
The big advantage of using Python's built-in sqlite3 module is that it is built-in; there are no other dependencies. If your app uses pyodbc and SQLite ODBC then both of those external components must be available for the application to function.
If this is a personal project then you can obviously install what is necessary, but if this is ever going to be widely deployed then you will need to deal with the additional requirements if you choose pyodbc. Specifically, your [Python] app can register a dependency on pyodbc such that pip install your_app also installs pyodbc, but it cannot (practically) accommodate the requirement for the SQLite ODBC driver automatically so your installation instructions will need to address that.
And is the pyodbc driver integrated in sqlite3?
No. The SQLite ODBC driver is completely separate from both Python [sqlite3] and pyodbc.
I have tried connecting exadata from python using cx_Oracle, but faced issue stating
cx_Oracle.DatabaseError: DPI - 1047: Cannot locate a 64bit Oracle client library.
I am trying to install a 64bit cx_Oracle, but I need to know can I connect from python to exadata.
Follow the cx_Oracle Linux installation instructions. The piece you are missing is access to Oracle Client libraries. As noted in the other answer, using Instant Client is the way to go. You'll need the "Basic" or "Basic Light" package for Linux x86-64. If you don't know your character set requirement, then use "Basic". You can use the latest 19c version. This will let you connect to Oracle DB 11.2 and newer.
If you have root access (?) you may find the RPM packages easier. If you want to use ZIP files, unzip the package, set your LD_LIBRARY_PATH environment variable to the directory, and run Python.
In your cx_Oracle scripts you use the same database credentials and connection string that you would use in SQL*Plus.
Welcome to Stack Overflow!
For the record, Oracle Exadata is a platform consisting of hardware and software designed for extreme Oracle Database performance. cx_Oracle is the Python client library to operate on an Oracle Database - hence you want to connect to an Oracle Database utilizing the Python programming language.
cx_Oracle depends on OCI (Oracle Call Interface). You need to download and install Oracle Client Library on your workstation before you can do import cx_Oracle from within Python.
You will find the Oracle Client Library here
Best of luck!
I am re-writng a perl program using python. In the perl program, it’s using perl database interface (DBI) to perform Oracle database operations. For example, DBI->connect to connect a database, and then prepare() the sql query and then execute() the query and fetch() results. I am wondering if Python has similar official module or other means to do the same things? I am using python 2.4 and 2.6 on two different RHEL 6.3 envs. Thanks in advance!
For SQLite3, there is the built-in sqlite3 module: http://docs.python.org/2/library/sqlite3.html
For PostgreSQL, there is psycopg2: http://initd.org/psycopg/
For MySQL, there is MySQLdb: http://mysql-python.sourceforge.net/MySQLdb.html
For MS SQL Server, there is pyodbc: http://code.google.com/p/pyodbc/
...or http://code.google.com/p/pymssql/
For Oracle:
https://wiki.python.org/moin/Oracle
http://www.oracle.com/technetwork/articles/dsl/python-091105.html
http://cx-oracle.sourceforge.net
PEP249, which #falsetru has mentioned, is more like an abstract description of a what a the API of a standards-conformant Python DB driver should look like. It is however in a way similar to DBI in that many (if not most or all) DB drivers for Python do have a very similar API, just like how DBI allows you to connect to many RDBMSes using a uniform API.
PLUG: take a look at Pony ORM also—it's an awesome new ORM with Oracle support: http://ponyorm.com.
Currently Pony supports 4 types of databases: 'sqlite', 'mysql', 'postgresql' and 'oracle'
It supports Python versions 2.5 or greater, but you can just use pythonz, pyenv to easily install any Python version without root privileges, or Conda.
I'd like to query a MySQL database using Python, but evidently the MySQLdb package requires a huge toolchain of MySQL stuff to be separately installed.
How can I query a MySQL database using a Python script without installing a bunch of unnecessary MySQL stuff, including conferring MySQL server capability on the client machine?
I don't love Perl, but it appears that the DBI package allows a Perl script to interface with MySQL without any MySQL stuff external to the package. I'm looking for something similar for Python.
You need to find a pure mysql python library. I have seen a couple over the last couple months. A quick google search yoelded pymysql. It has a large following on github. It looks promising. Pymysql is a pure python mysql client.
https://github.com/petehunt/PyMySQL
MySQLdb is just one of the available database drivers. It requires all that extra installation stuff, because it compiles c extensions and is one of the faster options.
There are a handful of other database drivers, some of which are pure-python.
The SqlAlchemy project has one of the more up-to-date collections of database drivers:
http://docs.sqlalchemy.org/en/latest/core/engines.html
PyMysql is a pure python driver, so it won't need to be built against the local MySql library.
I have a Firebird DB set up on my computer and I want to be able to retrieve data from a different computer. What is the best way to go about this?
I am running windows and using python.
Install firebird client to the client pc
To connect firebird programmaticaly from python you should install a python Firebird driver.
For Python 2.x, you can use kinterbasdb. This is the legacy driver and I think it is not actively developed but only maintained.
To connect windows based server database from kinterbasdb you can use
Import kinterbasdb as k
k.init(type_conv = 300) #
con = k.connect(dsn='127.0.0.1:c:\\db\\test.fdb', user='sysdba', password='masterkey', charset='YOUR_CHARSET', dialect=3)
Of course you should adjust connection parameters according to your system. Kinterbasdb documentation is here
If you want use an ORM, you can use SqlAlchemy which uses kinterbasdb for Firebird Support
For Python 3k you can use pyfirebirdsql which also supports Python 2.5+ and under active development, but not supported by SqlAlchemy yet.
Run Firebird server on the computer with database file and connect to it from remote computer. You will need in Firebird client library installed on remote computer.
I think we need a bit more info.
Do you want database access - as in "I want to be able to edit table layout and define new tables, views, procedures and so on" ?
Or do you only need to get data from the database using python ?
The latter could be achieved by installing a Firebird client (in essence its a dll (fbclient.dll)) and then use a connect string from python to connect to your database.