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: https://datatofish.com/how-to-connect-python-to-sql-server-using-pyodbc/

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

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=server_name;'
                      'Database=db_name;'
                      'Trusted_Connection=yes;')

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: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

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!