Update secrets value using custom code

Mmmm not what i need, look, i have the access token an the refresh token of other API. The thing is, this values are input in my custom code as secret, but the custome code needs to change the access token using the refresh token when the AT fails in the authentication process. so… how can i change these secrets using python as my programming lenguage in the custome code??