WikiLink API Reference¶
pycomptox.chemical.wikilink.WikiLink
¶
Bases: CachedAPIClient
Client for accessing Wikipedia GHS Safety data links from EPA CompTox Dashboard.
This class provides methods for checking if Wikipedia has GHS Safety data for chemicals and retrieving the corresponding Wikipedia URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
CompTox API key. If not provided, will attempt to load from saved configuration or COMPTOX_API_KEY environment variable. |
None
|
base_url
|
str
|
Base URL for the CompTox API. Defaults to EPA's endpoint. |
'https://comptox.epa.gov/ctx-api'
|
time_delay_between_calls
|
float, **kwargs
|
Delay in seconds between API calls for rate limiting. Default is 0.0 (no delay). |
0.0
|
Example
from pycomptox import WikiLink wiki = WikiLink()
Check if Wikipedia has GHS data for Bisphenol A¶
result = wiki.check_existence_by_dtxsid("DTXSID7020182") if result['safetyUrl']: ... print(f"Wikipedia GHS data: {result['safetyUrl']}")
Source code in src/pycomptox/chemical/wikilink.py
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
__init__(api_key=None, base_url='https://comptox.epa.gov/ctx-api', time_delay_between_calls=0.0, **kwargs)
¶
Initialize the WikiLink client.
Source code in src/pycomptox/chemical/wikilink.py
check_existence_by_dtxsid(dtxsid, use_cache=None)
¶
Check if Wikipedia has GHS Safety data for a chemical by DTXSID.
Returns the Wikipedia URL if GHS (Globally Harmonized System) safety data is available for the specified chemical, otherwise returns empty safetyUrl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtxsid
|
str
|
CompTox substance identifier (e.g., "DTXSID7020182") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
Wikipedia link information with fields: - dtxsid: DSSTox Substance Identifier - safetyUrl: Wikipedia URL for GHS safety data (or empty string if not available) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If chemical not found or invalid DTXSID |
RequestException
|
For API errors |
Example
wiki = WikiLink() result = wiki.check_existence_by_dtxsid("DTXSID7020182") print(f"DTXSID: {result['dtxsid']}") if result['safetyUrl']: ... print(f"Wikipedia GHS Safety URL: {result['safetyUrl']}") ... else: ... print("No Wikipedia GHS data available")
Example output:¶
DTXSID: DTXSID7020182¶
Wikipedia GHS Safety URL: https://en.wikipedia.org/wiki/IISBACLAFKSPIT-UHFFFAOYSA-N#section=wiki-Classification¶
Source code in src/pycomptox/chemical/wikilink.py
check_existence_by_dtxsid_batch(dtxsids, use_cache=None)
¶
Check Wikipedia GHS Safety data availability for multiple chemicals in a single request.
Batch retrieval of Wikipedia URLs for up to 1000 chemicals. More efficient than
making individual requests when checking multiple chemicals.
Args:
dtxsids (List[str]): List of CompTox substance identifiers
(maximum 1000 DTXSIDs)
Returns:
List[dict]: List of Wikipedia link information dictionaries, each containing:
- dtxsid: DSSTox Substance Identifier
- safetyUrl: Wikipedia URL for GHS safety data (or empty string if not available)
Raises:
ValueError: If more than 1000 DTXSIDs provided
requests.exceptions.RequestException: For API errors
Example:
>>> wiki = WikiLink()
>>> dtxsids = ["DTXSID7020182", "DTXSID2021315", "DTXSID5020001"]
>>> results = wiki.check_existence_by_dtxsid_batch(dtxsids)
>>>
>>> for result in results:
... status = "✓ Has data" if result['safetyUrl'] else "✗ No data"
... print(f"{result['dtxsid']}: {status}")
... if result['safetyUrl']:
... print(f" URL: {result['safetyUrl']}")
>>>
>>> # Count chemicals with Wikipedia GHS data
>>> with_data = sum(1 for r in results if r['safetyUrl'])
>>> print(f"
{with_data}/{len(results)} chemicals have Wikipedia GHS data")