code: def attach(session_type, address=None, port=None,
             path=None, argv=None, decode=None):
      
      session = (tcp_session(address, port) if session_type == 'tcp' else
                 socket_session(path) if session_type == 'socket' else
                 stdio_session() if session_type == 'stdio' else
                 child_session(argv) if session_type == 'child' else
                 None)
  
      if not session:
          raise Exception('Unknown session type "%s"' % session_type)
  
      if decode is None:
          decode = IS_PYTHON3
  
      return Nvim.from_session(session).with_decode(decode)
docs: Provide a nicer interface to create python api sessions.
  
      Previous machinery to create python api sessions is still there. This only
      creates a facade function to make things easier for the most usual cases.
      Thus, instead of:
          from pynvim import socket_session, Nvim
          session = tcp_session(address=<address>, port=<port>)
          nvim = Nvim.from_session(session)
      You can now do:
          from pynvim import attach
          nvim = attach('tcp', address=<address>, port=<port>)
      And also:
          nvim = attach('socket', path=<path>)
          nvim = attach('child', argv=<argv>)
          nvim = attach('stdio')
  
      When the session is not needed anymore, it is recommended to explicitly
      close it:
         nvim.close()
      It is also possible to use the session as a context mangager:
         with attach('socket', path=thepath) as nvim:
             print(nvim.funcs.getpid())
             print(nvim.current.line)
      This will automatically close the session when you're done with it, or
      when an error occured.