How to connect to SQL server 2017 from mac using python pyodbc

I develop a pet project using python and SQL server. I just solved a problem connecting to SQL server from python using pyodbc.

The short explanation is that pyodbc requirers SQL driver which is available for free from Microsoft.

If you wish to follow this guide you should have brew installed on your mac before you start.

There is a useful guide which explains how to use pyodbc here:

when I tried to connect the SQL server using the connection function - 

conn = pyodbc.connect('Driver={SQL Server};'

I received the following error:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")

The problem is with the driver "SQL Server".

To solve this issue I followed the guide provided by Microsoft:

I modified the connection string to use the new ODBC driver 

Driver={ODBC Driver 17 for SQL Server};Server=localhost;Database=myDatabase;UID=myUser;PWD=p@55word123;

Problem solved!