Linux only solution.
On Linux Systems, you can use Python to execute a command on the shell. I think it might help someone.
Something like this, (assuming 'dig/drill' is working on the os)
import os
command = "dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F\'\"\' '{print $2}' "
ip = os.system(command)
For Arch users, please replace 'dig' with 'drill'.