code: def connect_to_agent(env=None, sp=subprocess):
      
      sock_path = get_agent_sock_path(sp=sp, env=env)
      # Make sure the original gpg-agent is running.
      check_output(args=['gpg-connect-agent', '/bye'], sp=sp)
      sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
      sock.connect(sock_path)
      return sock
docs: Connect to GPG agent's UNIX socket.