def toApiObject(nodeName, dagPlugs=True): 
    sel = MSelectionList()
    try:
        sel.add( nodeName )
    except:
        if "." in nodeName :
            # Compound Attributes
            #  sometimes the index might be left off somewhere in a compound attribute 
            # (ex 'Nexus.auxiliary.input' instead of 'Nexus.auxiliary[0].input' )
            #  but we can still get a representative plug. this will return the equivalent of 'Nexus.auxiliary[-1].input'
            try:
                buf = nodeName.split('.')
                obj = toApiObject( buf[0] )
                if isinstance(obj,MDagPath):
                    mfn = MFnDagNode(obj)
                else:
                    mfn = MFnDependencyNode(obj)
                plug = mfn.findPlug( buf[-1], False )
                
                if dagPlugs: # and isValidMDagPath(obj) : 
                    return (obj, plug)
                return plug
            except (RuntimeError,ValueError):
                return
    else:
        if sel.length() != 1:
            return None
        if "." in nodeName :
            try:
                # Plugs
                plug = MPlug()
                sel.getPlug( 0, plug )
                if dagPlugs:
                    try:
                        # Plugs with DagPaths
                        sel.add( nodeName.split('.')[0] )
                        dag = MDagPath()
                        sel.getDagPath( 1, dag )
                        #if isValidMDagPath(dag) :
                        return (dag, plug)
                    except RuntimeError: pass
                return plug
            
            except RuntimeError:
                # Components
                dag = MDagPath()
                comp = MObject()
                try:
                    sel.getDagPath( 0, dag, comp )
                except RuntimeError:
                    pass
                #if not isValidMDagPath(dag) :   return
                if not comp.isNull():
                    return (dag, comp)
                # We may have gotten a published container attribute, which
                # auto- magically converts to the contained node it references
                # when added to an MSelectionList
                splitName = nodeName.split('.')
                # Thankfully, it seems you can't index / get children off an
                # aliased attribute - ie, myNode.myAlias[0] and
                # myNode.myAlias.childAttr don't work, even if myAlias point
                # to a multi / compound attr
                if len(splitName) == 2:
                    obj = MObject()
                    try:
                        sel.add( splitName[0] )
                        sel.getDependNode(1, obj)
                    except RuntimeError:
                        pass 
                    else:
                        # Since it seems there's no api way to get at the plug for
                        # a published / aliased container attr, we just check for
                        # aliases...
                        mfn = MFnDependencyNode(obj)
                        aliases = []
                        if mfn.getAliasList(aliases):
                            for aliasName, trueName in util.pairIter(aliases):
                                if aliasName == splitName[1]:
                                    return toApiObject('.'.join( (splitName[0], trueName) ))
        else:
            try:
                # DagPaths
                dag = MDagPath()
                sel.getDagPath( 0, dag )
                #if not isValidMDagPath(dag) : return
                return dag
         
            except RuntimeError:
                # Objects
                obj = MObject()
                sel.getDependNode( 0, obj )          
                #if not isValidMObject(obj) : return
                return obj
Get the API MPlug, MObject or (MObject, MComponent) tuple given the name of an existing node, attribute, components selection
dataset/ETHPy150Open CountZer0/PipelineConstructionSet/python/maya/site-packages/pymel-1.0.3/pymel/api/allapi.py/toApiObject