-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextract_api_structure.py
More file actions
75 lines (61 loc) · 2.26 KB
/
Copy pathextract_api_structure.py
File metadata and controls
75 lines (61 loc) · 2.26 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import inspect
import json
import os
from pathlib import Path
import ctxpy as ctx
# Initialize with API key from environment
api_key = os.environ.get("CTX_API_KEY") or os.environ.get("EPA_COMPTOX_API_KEY")
if not api_key:
raise SystemExit(
"Missing CTX_API_KEY (or EPA_COMPTOX_API_KEY). Set your key in the environment to run this extractor."
)
# Extract Chemical module structure
def extract_class_methods(cls, instance=None):
methods = {}
for name, method in inspect.getmembers(cls, inspect.isfunction):
if not name.startswith("_"): # Skip private methods
if instance:
# Get method signature
sig = str(inspect.signature(getattr(instance, name)))
methods[name] = sig
else:
methods[name] = "No signature available"
return methods
# Extract structure for all main modules
api_structure = {}
# Chemical module
try:
chem = ctx.Chemical(x_api_key=api_key)
api_structure["Chemical"] = extract_class_methods(ctx.Chemical, chem)
except Exception as e:
api_structure["Chemical"] = {"error": str(e)}
# Exposure module
try:
expo = ctx.Exposure(x_api_key=api_key)
api_structure["Exposure"] = extract_class_methods(ctx.Exposure, expo)
except Exception as e:
api_structure["Exposure"] = {"error": str(e)}
# Hazard module
try:
haz = ctx.Hazard(x_api_key=api_key)
api_structure["Hazard"] = extract_class_methods(ctx.Hazard, haz)
except Exception as e:
api_structure["Hazard"] = {"error": str(e)}
# ChemicalList module
try:
chem_list = ctx.ChemicalList(x_api_key=api_key)
api_structure["ChemicalList"] = extract_class_methods(ctx.ChemicalList, chem_list)
except Exception as e:
api_structure["ChemicalList"] = {"error": str(e)}
# Cheminformatics functions
api_structure["Cheminformatics"] = {
"search_toxprints": str(inspect.signature(ctx.search_toxprints))
}
# Save to an ignored local artifact path so ad hoc snapshots do not clutter the repo root.
output_path = (
Path(__file__).resolve().parent / "artifacts" / "epa_comptox_api_structure.json"
)
output_path.parent.mkdir(parents=True, exist_ok=True)
with output_path.open("w") as f:
json.dump(api_structure, f, indent=2)
print(f"API structure extracted and saved to {output_path}")