Appearance
Getting started
You need Python 3.9 or later and a Gosset account with API access.
Install
bash
python -m pip install --upgrade "gosset>=0.5.22"The same package provides the Python SDK and the gosset command.
Authenticate
Set your account's API token in the environment:
bash
export GOSSET_API_KEY="your-api-token"For interactive use, you can also run gosset login and complete the browser login. The SDK can use the locally saved login. For scheduled jobs, use an environment variable supplied by your deployment's secret settings.
python
from gosset import GossetClient
client = GossetClient(timeout=120)You can supply a token directly with GossetClient(api_key=token). Keep real tokens out of source files and shared notebooks.
Make a request
python
from gosset import GossetClient
with GossetClient(timeout=120) as client:
page = client.query(
"trials",
where={"field": "drug", "op": "is", "value": "pembrolizumab"},
fields=["nct_id", "title", "phase", "status"],
limit=5,
)
for trial in page["results"]:
print(trial["nct_id"], trial["title"])Use programmatic data access for filters and pagination, or go to the PTRS guide for predictions.
Handle errors
python
from gosset import GossetClient, GossetAPIError
try:
with GossetClient(timeout=120) as client:
page = client.query("drugs", limit=5)
except ValueError as error:
print("Check the request parameters:", error)
except GossetAPIError as error:
print("The request could not be completed:", error)Check your token for authentication errors, your account access for permission errors, and the requested fields for validation errors. For rate limits, wait before retrying and reduce request frequency.