File size: 1,034 Bytes
8620228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import inspect

def get_api_info(api):
    try:
        # Split the API string into module and function parts
        module_parts = api.split('.')
        function_name = module_parts.pop()
        module_name = '.'.join(module_parts)

        # Dynamically import the module
        module = __import__(module_name, fromlist=[function_name])
        
        # Get the function or class from the module
        api_object = getattr(module, function_name)

        # Get the signature
        signature = inspect.signature(api_object)

        # Get the docstring
        docstring = inspect.getdoc(api_object)

        return {
            'name': api,
            'signature': str(signature),
            'docstring': docstring
        }
    except ImportError:
        return {'name': api, 'error': 'Module not found'}
    except AttributeError:
        return {'name': api, 'error': 'Function or class not found in module'}
    except Exception as e:
        return {'name': api, 'error': str(e)}