Using BI connector in python

hi there,
Is there a way to use BI connector inside the python program to write SQL queries… Just curious.

Hi @Prem_Singh - that’s a great question - and the answer is yes. The BI connector emulates a MySQL server, but on top of MongoDB, so you can use any compatible MySQL driver for Python to connect to your data from Python. Here’s an example I wrote for connecting to our open COVID-19 data set.

Let me know if you have any problems.

Mark

1 Like

Hi @Mark_Smith ,
The above is not working, as it is giving Authentication plugin ‘mongosql_auth’ is not supported

def main():
    import mysql.connector
    try:
        connection = mysql.connector.connect(user='readonly', password='myreads',
                                             host='Mongo Bi host',
                                             port='3307',

                                             database='insightsdb',
                                             auth_plugin='mongosql_auth')
        cursor = connection.cursor()
        query = "SELECT * from global_and_us limit 20"
        cursor.execute(query)

        for i in cursor:
            print(i)

        cursor.close()
        connection.close()
    except Exception as e:
        print(e)

Can you please help?