See https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#CellData and https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#TextFormatRun for how to do this.
See https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#RepeatCellRequest for how to apply the formatting to multiple cells at once, if you need to do that.
I personally haven't tried the TextFormatRun capabilities, but as a more generic example, here's how you change the color of the background and foreground, alignment, and boldness of a row:
def sheets_batch_update(SHEET_ID,data):
print ( ("Sheets: Batch update"))
service.spreadsheets().batchUpdate(spreadsheetId=SHEET_ID,body=data).execute() #,valueInputOption='RAW'
data={
"requests": [
#format header row
{
"repeatCell": {
"range": {
"sheetId": all_sheets['Users'],
"startRowIndex": 0,
"endRowIndex": 1
# "startColumnIndex": 0,
# "endColumnIndex": 6
},
"cell": {
"userEnteredFormat": {
"backgroundColor": {
"red": 0.4,
"green": 0.4,
"blue": 0.4
},
"horizontalAlignment" : "LEFT",
"textFormat": {
"foregroundColor": {
"red": 1.0,
"green": 1.0,
"blue": 1.0
},
#"fontSize": 12,
"bold": True
}
}
},
"fields": "userEnteredFormat(backgroundColor,textFormat,horizontalAlignment)"
}
},
]
}
sheets_batch_update(SHEET_ID, data)