Coverage for mindsdb / integrations / handlers / npm_handler / api.py: 0%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-21 00:36 +0000

1import requests 

2 

3 

4class NPM: 

5 

6 def __init__(self, package_name: str): 

7 resp = requests.get("https://api.npms.io/v2/package/" + package_name) 

8 if not resp or resp.status_code != 200: 

9 raise Exception(f"Unable to get package datails: '{package_name}'") 

10 self.data = resp.json() 

11 

12 def get_data(self): 

13 return self.data 

14 

15 @staticmethod 

16 def is_connected(): 

17 return True if requests.get("https://api.npms.io/v2/search?q=a&size=1").status_code == 200 else False 

18 

19 def get_cols_in(self, path, cols): 

20 curr_root = self.data 

21 for p in path: 

22 curr_root = curr_root[p] 

23 req_cols = {} 

24 for col in cols: 

25 req_cols[col] = curr_root[col] if col in curr_root else {} 

26 return req_cols