API Client
The EpiSuiteAPIClient class provides the core interface for interacting with the EPISuite API.
By default, the client now prefers a local runtime when data/local/EpiSuiteCLI.jar is available.
Set PYEPISUITE_MODE=remote to force the hosted API.
Overview
pyepisuite.api_client.EpiSuiteAPIClient
Source code in src/pyepisuite/api_client.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
search(query_term, time_out=10)
Search the EPISuite API with a query term (SMILES, CAS, or chemical name).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query_term
|
str
|
The term to search for. |
required |
time_out
|
int
|
The time out for the request. |
10
|
Returns:
| Type | Description |
|---|---|
|
List[Chemical]: A list of Chemical instances. |
Source code in src/pyepisuite/api_client.py
stop_local_runtime()
staticmethod
submit(cas='', smiles='')
Submit a CAS number or SMILES string to the EPISuite API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cas
|
str
|
The CAS number of the chemical. |
''
|
smiles
|
str
|
The SMILES string of the chemical. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The JSON response from the API. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither 'cas' nor 'smiles' is provided. |
Source code in src/pyepisuite/api_client.py
Usage Examples
Basic Client Setup
from pyepisuite import EpiSuiteAPIClient
# Create client with default settings.
# If a local JAR is present, this starts local mode automatically.
client = EpiSuiteAPIClient()
# Or with custom base URL
client = EpiSuiteAPIClient(base_url='https://episuite.dev/EpiWebSuite/api')
# With API key (if required)
client = EpiSuiteAPIClient(api_key='your-api-key')
Explicit Local Client
from pyepisuite import LocalEpiSuiteAPIClient, stop_local_episuite_server
# Always target local runtime.
client = LocalEpiSuiteAPIClient()
ids = client.search('formaldehyde')
result = client.submit(cas='000050-00-0')
# Stop managed local process when needed.
stop_local_episuite_server()
Mode Selection
Use PYEPISUITE_MODE to control behavior:
auto(default): prefer local runtime if JAR exists, otherwise use remote APIlocal: require local runtime and fail fast if startup failsremote: always use hosted API
Optional local environment variables:
PYEPISUITE_LOCAL_JAR_PATH: absolute/relative path toEpiSuiteCLI.jarPYEPISUITE_LOCAL_BASE_URL: connect-only mode, e.g.http://127.0.0.1:45511PYEPISUITE_LOCAL_STARTUP_TIMEOUT: startup timeout in seconds (default60)
Searching for Chemicals
# Search by CAS number
results = client.search('50-00-0')
# Search by SMILES
results = client.search('C=O')
# Search by chemical name
results = client.search('formaldehyde')
Submitting for Predictions
# Submit using CAS number
predictions = client.submit(cas='50-00-0')
# Submit using SMILES
predictions = client.submit(smiles='C=O')
# The response includes both EPI Suite and EcoSAR results
print(predictions.keys()) # ['chemicalProperties', 'logKow', ..., 'ecosar']
Error Handling
The API client includes robust error handling:
import requests
try:
results = client.search('invalid-identifier')
except requests.exceptions.RequestException as e:
print(f"API request failed: {e}")
except ValueError as e:
print(f"Invalid parameters: {e}")
Configuration Options
Timeout Settings
API Key Authentication
If the API requires authentication:
Related Functions
For higher-level operations, see the utility functions: