Save output from async function, and store it to MySQL database

23 views Asked by At

I am working on making a API call and saving the data and storing it to MySQL database using Python.

Below is a portion of my code:

async def main():
    user = input("Enter username: ")
    pwd = getpass.getpass()
    session_header = {
        "Accept":     "application/json",
        "Content-Type": "application/json",
    }         
    with Bar(
        "Generating",
        max=(len(APIs.keys()) *   5),
        suffix="%(percent)d%%",
    ) as progress_bar:
        for instance in     APIs.keys():
            async with    httpx.AsyncClient(                    
            verify=False,
            auth=(user, pwd),
            headers=session_header,
            timeout=None,
            ) as async_session:
            progress_bar.next()
            state = await get_instance_state(instance, async_session)
            progress_bar.next()
            data = await get_vm_data(instance, state, async_session)
            progress_bar.next()
        table = create_table(data)
        print (table); 
        #I am getting data(df) till here
if __name__ == "__main__":
    asyncio.run(main())

Now I want to create a list from above (table = create_table(data) here: (Please help how to do this)

MyList = []

then want to use sql.connector to connect to database and INSERT those data data to MySQL database (Please help how to do this)

I get the values from API, and able to print the data. Now I need help storing them to MySQL database.

Now I want to insert that data to MySQL database.

0

There are 0 answers