import inspect from importlib.util import spec_from_file_location, module_from_spec script_path = "test.py" spec = spec_from_file_location("test", script_path) module = module_from_spec(spec) spec.loader.exec_module(module) print(module) members = inspect.getmembers(module, lambda member: not inspect.ismodule(member)) members = [(name, value) for name, value in members if not name.startswith('_')] print(members)