To encode/decode a domain using "Internationalized Domain Names"

$ python
>>> x = u'qép.com'
>>> x.encode('idna')
b'xn--qp-bja.com'
>>> x.encode('idna').decode('idna')
'qép.com'
>>> x == x.encode('idna').decode('idna')
True

To prevent non-international domain names containing hyphens from being accidentally interpreted as Punycode, international domain name Punycode sequences have a so-called ASCII Compatible Encoding (ACE) prefix, "xn--", prepended.[2] Thus the domain name "bücher.tld" would be represented in ASCII as "xn--bcher-kva.tld".