Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python & sql server

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 ?

like image 549
dan Avatar asked Feb 22 '10 21:02

dan


4 Answers

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.

like image 167
van Avatar answered Oct 04 '22 14:10

van


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

like image 21
mmmmmm Avatar answered Oct 04 '22 14:10

mmmmmm


Also could someone provide a such code using the DB-API 
how to connect to sql server from python and excute query ?

This hello world snippet pretty much shows you the common way how to connect with SQL server in Python with an DBI 2.0 database interface module.

Disclaimer: I'm the developer of pypyodbc

like image 32
pypyodbc Avatar answered Oct 04 '22 15:10

pypyodbc


ODBC + freetds + a python wrapper library for ODBC.

like image 38
Hassan Syed Avatar answered Oct 04 '22 13:10

Hassan Syed