Here is a simplified version using config.json for what you want to do. Note this creates malformed JSON so you might want to edit a bit.
config.py creates config.json file from config python dict by writing to file with standard lib json.
import json
config = {"cfg_x": {"example": "old value"}, "cfg_y": 1031, "cfg_Z": "Hello"}
with open('config.json', 'w') as file:
json.dump(config, file)
created file
~/Desktop/octocat » cat config.json
{"cfg_x": {"example": "old value"}, "cfg_y": 1031, "cfg_Z": "Hello"}% (venv1)
myproj.py opens with config.json read mode 'r' changes nested key and writes to file.
import json
with open('config.json', 'r') as file:
config = json.load(file)
config["cfg_x"]["example"] = "different value"
with open('config.json', 'w') as file:
json.dump(config, file)
modified file.
~/Desktop/octocat » cat config.json
\{"cfg_x": {"example": "different value"}, "cfg_y": 1031, "cfg_Z": "Hello"}% (venv1)
In real prod scenario, I would generally use 1 of million Python config libs that already exists rather than something like this. Here is an example: https://jbasko.github.io/configmanager/
If you use this, the bare minimum you want to modify config.py to check if the file already exists rather than overwriting the whole config.json.