import re, sre_parse
pattern = (
    '(?P<DEF_FUNC>def (?P<NAME_FUNC>\\w+)\\s*\\((.*?)\\):)|(?P<OTHERS>\\w+)')
v = sre_parse.parse(pattern)
print(v.pattern.groupdict)
Pattern associated to a named group