Untested:
from ctypes import *
ComputerNamePhysicalDnsHostname = 5
computer_name = u'COMPUTER'
success = windll.kernel32.SetComputerNameExW(ComputerNamePhysicalDnsHostname,
computer_name)
if success:
print("Name changed")
else:
print("Failed")
The process will need admin rights, and the computer will need to be
rebooted before the change will take effect.