Here is what I use to get usage rates
LOGIN = # paste your login
PASSWORD = # paste your password g
sg = SendGridAPIClient(PASSWORD, impersonate_subuser = "")
response = sg.client.user.credits.get() today = date.today()
ddate = today.strftime("%Y-%m-%d")
d = datetime.today() - timedelta(days=n)
ddate2 = d.strftime("%Y-%m-%d")
tdate=d.strftime("%m-%d-%Y")
params = {'aggregated_by': 'day', 'limit': 1,
'start_date': ddate2, 'end_date': ddate2, 'offset': 1}
response = sg.client.stats.get(query_params=params)
datas=json.loads(response.body)
tdate = today.strftime("%m-%d-%y")
print(tdate)
sent=datas[0]['stats'][0]['metrics']['requests']
open=datas[0]['stats'][0]['metrics']['unique_opens']
remain=100-int(sent)
print(f"Emails sent today = {sent}, with {remain} remaining in daily limit")
if sent==0:
percentage="{:.0%}".format(0)
else:
percentage = "{:.0%}".format(open/sent)
print(f"Open rate on this date is {percentage} ")