Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ DATABASE_URI=postgresql://postgres:postgres@localhost:5432/atol_db
JWT_SECRET_KEY=
JWT_ALGORITHM=HS256
# BACKEND_CORS_ORIGINS=["http://localhost:3000","http://localhost:8000"]

# NCBI API key
NCBI_API_KEY=
3 changes: 3 additions & 0 deletions app/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Settings(BaseSettings):
ENVIRONMENT: Optional[str] = None # Options: "dev", "prod"
APP_VERSION: str = "dev"

# NCBI api key
NCBI_API_KEY: Optional[str] = None

# Model config
model_config = SettingsConfigDict(
env_file=".env",
Expand Down
10 changes: 8 additions & 2 deletions app/services/ncbi_taxonomy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import requests

from app.core.settings import settings

logger = logging.getLogger(__name__)

# Adapted from:
Expand Down Expand Up @@ -55,12 +57,16 @@ def fetch_reports(
) -> list[dict[str, Any]]:
"""Fetch taxonomy report dicts for a batch of tax_ids."""
url = build_taxonomy_url(tax_ids, endpoint)
logger.info("Fetching NCBI %s reports for tax_ids=%s", endpoint, tax_ids)
request_params = {}
if settings.NCBI_API_KEY:
request_params["api_key"] = settings.NCBI_API_KEY

logger.info("Fetching NCBI %s reports for tax_ids=%s", endpoint, tax_ids)

for attempt in range(1, max_retries + 1):
try:
with _ncbi_semaphore:
response = requests.get(url, timeout=timeout_seconds)
response = requests.get(url, timeout=timeout_seconds, params=request_params)
response.raise_for_status()
payload = response.json()
reports = payload.get("reports", [])
Expand Down
Loading