views:

162

answers:

3

What is the best way to access sql server from python is it DB-API ? Also could someone provide a such code using the DB-API how to connect to sql server from python and excute query ?

+2  A: 

See pymssql It is a DB-API module for MS Sql Server and would be the most pythonic way. The documentation includes examples.

If on a Windows OS you could also use OLEDB through COM which will not require any thing else to be installed on the client.

Also if you use Iron Python you can use the .Net APIs

Mark
+5  A: 

See pyodbc - Python Database API Specification v2.0 implementation. Works great.

Additionally you can use it with other databases. If using with SQL Server 2008, make sure you use Native Driver if you need to support new DATE data types.

van
I have a data conversion project that uses pyodbc with SQL Server, and it works great.
Mark Ransom
+1  A: 

ODBC + freetds + a python wrapper library for ODBC.

Hassan Syed