Skip to main content

Python client library for Supplement Advisor API

Project description

Supplement Advisor API Client

A simple Python client library for the Supplement Advisor API that helps you analyze supplement suitability for user profiles.

Installation

pip install supplement-advisor-client

Quick Start

from supplement_advisor_client import analyze_supplement

api_key = "your-api-key"
ingredient_id = "coq10"
user_profile = {
    "age_range": "25-34",
    "sex": "female",
    "diet_type": "vegetarian",
    "goals": ["energy", "heart_health"],
    "conditions": [],
    "medications": [],
    "pregnancy_status": "none"
}

result = analyze_supplement(api_key, ingredient_id, user_profile)
print(f"Score: {result['overall_score']}")
print(f"Label: {result['suitability_label']}")
print(f"Risk Level: {result['risk_level']}")

API Reference

analyze_supplement(api_key, ingredient_id, user_profile)

Analyze supplement suitability for a user profile.

Parameters:

  • api_key (str): API key for authentication (X-API-Key header)
  • ingredient_id (str): ID of the supplement ingredient (e.g., 'coq10')
  • user_profile (dict): Dictionary containing user profile information:
    • age_range (str): Age range (e.g., '25-34')
    • sex (str): Sex (e.g., 'female', 'male')
    • diet_type (str): Diet type (e.g., 'omnivore', 'vegetarian', 'vegan')
    • goals (List[str]): List of health goals (e.g., ['energy', 'heart_health'])
    • conditions (List[str], optional): List of medical conditions (default: [])
    • medications (List[str], optional): List of current medications (default: [])
    • pregnancy_status (str): Pregnancy status (e.g., 'none', 'pregnant', 'breastfeeding')

Returns:

  • dict: Supplement analysis result containing:
    • overall_score (float): Suitability score from 0.0 to 1.0
    • suitability_label (str): Text label describing suitability
    • evidence_level (str): Evidence level (e.g., 'A', 'B', 'C')
    • risk_level (str): Risk level (e.g., 'low', 'medium', 'high', 'higher')
    • key_benefits (str): Key benefits description

Raises:

  • AuthenticationError: If API key is invalid (401/403)
  • RateLimitError: If rate limit is exceeded (429)
  • ServerError: If server error occurs (5xx)
  • APIError: If other API request fails

health_check

Check API health status (no authentication required).

Returns:

  • dict: Health status containing:
    • status (str): Status (e.g., 'healthy')
    • service (str): Service name (e.g., 'Supplement Advisor API')

Raises:

  • APIError: If API request fails

Error Handling

The client provides specific exception types for different error scenarios:

from supplement_advisor_client import (
    analyze_supplement,
    AuthenticationError,
    RateLimitError,
    ServerError,
    APIError,
)

try:
    result = analyze_supplement(api_key, ingredient_id, user_profile)
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except RateLimitError as e:
    print(f"Rate limit exceeded: {e}")
except ServerError as e:
    print(f"Server error: {e}")
except APIError as e:
    print(f"API error: {e}")

Examples

Using with Production API

from supplement_advisor_client import analyze_supplement

result = analyze_supplement(
    api_key="your-api-key",
    ingredient_id="coq10",
    user_profile={
        "age_range": "45-54",
        "sex": "male",
        "diet_type": "omnivore",
        "goals": ["heart_health"],
        "conditions": ["hypertension"],
        "medications": ["lisinopril"],
        "pregnancy_status": "none"
    }
)

Checking API Health

from supplement_advisor_client import health_check

status = health_check()
print(f"API Status: {status['status']}")

Requirements

  • Python 3.8+
  • requests >= 2.31.0

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supplement_advisor_client-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supplement_advisor_client-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file supplement_advisor_client-0.1.1.tar.gz.

File metadata

File hashes

Hashes for supplement_advisor_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4cfcbd66d16c1d018bb2e800376a68bc780bbba24cf88f5fddeaac64c308c259
MD5 5462b0340fc729ef4654e04e42c76d51
BLAKE2b-256 f3daa08b46030fb210b9cc0541caf2da6ac103b46f0f5a90b2f2218957c65645

See more details on using hashes here.

File details

Details for the file supplement_advisor_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for supplement_advisor_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87e26b9e59822b12ab3967b7dd86d616dd470e1faa024b4eba9d0ea5fee7784b
MD5 ff4dca093f6c33b88fef7dbbc9f6a9e6
BLAKE2b-256 f38d5a621b42125093c3556d67aef69779a915eb6741d54394a0bff5cc3720fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page