gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Using a custom json serialiser in worksheet.update

Open tlienart opened this issue 8 months ago • 1 comments

I'm using GSpread to write values from a (polars) dataframe into Google Sheet via worksheet.batch_update and would like to be able to specify the JSON serialiser when doing that. This would help when dealing with dates serialisation issues for instance.

In the context of batch_update, the trail is:

  • here the query is made via self.client.values_batch_update(...)
  • here is what it correspond to in the http_client code

The data=data here in the request method gives me hope that this

https://github.com/burnash/gspread/blob/6074285628c88f3a73d024cefd2f6691ad4391d6/gspread/http_client.py#L139

could maybe be replaced by something like

if json_serialiser is not None:
    r = self.request("post", SPREADSHEET_BATCH_UPDATE_URL % id, data=json_serialiser(body))
else:
    r = self.request("post", SPREADSHEET_BATCH_UPDATE_URL % id, json=body)

PS: I'm aware of https://github.com/robin900/gspread-dataframe but I thought ☝ seemed sufficiently generic to be opened here

tlienart avatar Jun 07 '25 20:06 tlienart

thanks for the suggestion !

we don't have much active coding right now from maintainers, but if you would like to implement this feature, go ahead and I will try to review it !

see the contributing guide: https://github.com/burnash/gspread/blob/master/.github/CONTRIBUTING.md

as this touches quite a crucial part of the library, I would want to see a fairly thorough test created

alifeee avatar Jun 09 '25 11:06 alifeee