I need to write a python application with use both of the mysql and sql server is there
a general python module or library that can access both mysql and sql server as DBI with perl or should i use 2 libraries and if yes which libraries do you recommend .
I guess you are looking for SQLAlchemy. You will probably need some time getting into it, but it is invaluable once you have covered the basics.
SQLAlchemy acts as a frontend to other, database-specific libraries using the Python DB-API -- but beyond this, it provides a query builder library that abstracts out differences between databases' SQL syntax and permits programmatic query construction while still offering the full power of SQL.
Python RDBMS modules implement DB-API.
If you are looking for which connection drivers to use, I believe the only one that well work for both [MySQL (driver here) and SQLServer (native to windows/FreeTDS for linux) is pyodbc. #igor has the right idea, though, use SQLAlchemy, you can connect to each database using different engines, but use the same code to interact with both.
Related
I am new to Python and using Enthought Canopy Express for learning purpose.
As part of that I am looking for an option to connect Canopy Express with SQL Server. Couldn't find any materials.
Please share methods for database connection for data collection?
PEP 249 defines a standard interface for database programming in Python. There are a number of Python packages implementing that interface that can help you connect with SQL Server. You might try looking at pyodbc. There are some others listed here
If you just want to get some experience using SQL statements in Python, you might want to start with the sqlite3 package.
I'm wondering if there is any built-in way in Python to test a MySQL server connection. I know I can use PyMySQL, MySQLdb, and a few others, but if the user does not already have these dependencies installed my script will not work? How can I write a Python script to test a MySQL connection without requiring external dependencies?
Python distributions do not include support for MySQL, which is only available by installing a third-party module such as PyMySQL or MySQLdb. The only relational support included in Python is for the SQLite database (in the shape of the sqlite3 module).
There is, however, nothing to stop you distributing a third-party module as a part of your application, thereby including the support your project requires. PyMySQL would probably be the best choice because, being pure Python, it will run on any platform and give you best portability.
Can i install and build postgreSQL from Source Code in Windows by using Python? Is it solid? Currently in their documentation they have Visual C++ as their only option!
And if it is possible (and reliable) where can i find prime material to use Python to build and customize my postgreSQL? I won't go and learn Visual C++ unless it is the only way. I also have GitBash if that helps...
For people who have no idea on db's. They never say that in documentations because they think it for granted.
IT ALL BOILS DOWN TO: It is another thing building_from_source/installing a db and a totally another thing interacting/working with a db.
There is library for accessing Postgres from python called psycopg. There is a tutorial on its use here.
To the extent that you are just learning about databases, you might also take a look at Sqlite, which is a more lightweight database and included in the python standard library
Since you want to use PostgreSQL you really don't need to compile anything. Simply install PostgreSQL and the windows binaries of psycopg2 (the PostgreSQL client library for python).
If you want to build the PostgreSQL database server - something you only want/need to do if you want to modify PostgreSQL itself, and which is something you probably don't want to do as a beginner - you should use whatever compiler the Postgres developers suggest since they most likely only have project/make files for that compiler.
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.