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, base_url="http://localhost:8000")

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')
  • base_url (str, optional): Base URL of the API server (default: 'http://localhost:8000')

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(base_url="http://localhost:8000")

Check API health status (no authentication required).

Parameters:

  • base_url (str, optional): Base URL of the API server (default: 'http://localhost:8000')

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"
    },
    base_url="https://api.supplementadvisor.com"  # Production URL
)

Checking API Health

from supplement_advisor_client import health_check

status = health_check(base_url="https://api.supplementadvisor.com")
print(f"API Status: {status['status']}")

Requirements

  • Python 3.8+
  • requests >= 2.31.0

License

MIT License

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

For issues and questions, please visit the GitHub repository.

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.0.tar.gz (5.5 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.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for supplement_advisor_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 96540287468bd54e6e1585476f06aed338a9a33913af3eb9f6426e68079c4f15
MD5 1847ee4d7ad0070fd00731036ce1811a
BLAKE2b-256 1bfa2fba2fe1ccb6b38a5acf1cd042eb39d2cc3d614f3634047220c4bcb1c2a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for supplement_advisor_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bf726702cb9bf9a518212661db228eba10683dfcc72570d63ee4de8cd522ee4
MD5 f22854f1d0797c7193ce93f34da08acd
BLAKE2b-256 7cc3c9476fd0e8f5061c7c9351e5923d21e7ae79a5b6f3535f65d0328ea97cd9

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