def docx_replace(old_file, new_file, rep):
    zin = zipfile.ZipFile(old_file, 'r')
zout = zipfile.ZipFile(new_file, 'w')
for item in zin.infolist():
    buffer = zin.read(item.filename)
if item.filename == 'word/document.xml':
    res = buffer.decode('utf-8')
for r in rep:
    res = res.replace(r, rep[r])
buffer = res.encode('utf-8')
zout.writestr(item, buffer)
zout.close()
zin.close()
Text-Replace in docx and save the changed file with python-docx