Skip to main content

Nutrition data and food composition API client — nutrifyi.com

Project description

nutrifyi

PyPI version Python License: MIT Zero Dependencies

Python API client for nutrition data and food composition analysis. Query macronutrient and micronutrient profiles, look up USDA food composition data, calculate Recommended Dietary Allowances (RDA), and compare nutrient density across foods — all from NutriFYI, a nutrition reference platform with comprehensive food composition data.

Built on USDA FoodData Central and international food composition databases, NutriFYI provides structured access to calories, protein, fat, carbohydrates, vitamins, minerals, and dietary fiber for thousands of foods — used by nutrition app developers, dietitians, and health-tech platforms.

Explore nutrition data at nutrifyi.com — browse foods, compare nutrients, and calculate dietary intake.

nutrifyi demo — food nutrition lookup, macronutrient analysis, and dietary comparison in Python

Table of Contents

Install

pip install nutrifyi                # Core (zero deps)
pip install "nutrifyi[cli]"         # + Command-line interface
pip install "nutrifyi[mcp]"         # + MCP server for AI assistants
pip install "nutrifyi[api]"         # + HTTP client for nutrifyi.com API
pip install "nutrifyi[all]"         # Everything

Quick Start

from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    # Get full nutrition profile for a food
    food = api.get_food("chicken-breast")
    print(food["calories"])          # 165 kcal per 100g
    print(food["protein"])           # 31.0g
    print(food["fat"])               # 3.6g

    # Search the food database
    results = api.search("quinoa")
    for r in results:
        print(f"{r['name']}: {r['calories']} kcal/100g")

    # List nutrient categories
    nutrients = api.list_nutrients()

What You Can Do

Macronutrient Profiles

The three macronutrients — protein, carbohydrates, and fat — provide the body's caloric energy. Each macronutrient serves distinct metabolic functions: protein for tissue building (4 kcal/g), carbohydrates for immediate energy (4 kcal/g), and fat for energy storage and hormone synthesis (9 kcal/g).

Macronutrient Energy RDA (Adult) Primary Function
Protein 4 kcal/g 0.8 g/kg body weight Tissue repair, enzymes, immune function
Carbohydrates 4 kcal/g 130 g/day Glucose for brain and muscles
Fat 9 kcal/g 20-35% of calories Cell membranes, hormones, fat-soluble vitamins
Fiber 0 kcal/g 25-38 g/day Gut health, cholesterol reduction
Water 0 kcal 2.7-3.7 L/day Every metabolic process
from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    # Full macronutrient breakdown per 100g
    food = api.get_food("salmon-atlantic")
    print(f"Calories: {food['calories']} kcal")
    print(f"Protein: {food['protein']}g")
    print(f"Fat: {food['fat']}g (Saturated: {food['saturated_fat']}g)")
    print(f"Carbs: {food['carbohydrates']}g")
    print(f"Fiber: {food['fiber']}g")

Learn more: Food Database · Glossary

Micronutrients (Vitamins and Minerals)

Micronutrients are required in small amounts but are essential for enzyme function, bone health, immune response, and cellular repair. They divide into fat-soluble vitamins (A, D, E, K — stored in body fat), water-soluble vitamins (B-complex, C — excreted daily), and minerals (macro and trace).

Category Nutrients Key Functions
Fat-soluble vitamins A, D, E, K Vision, bone health, antioxidant, coagulation
Water-soluble vitamins B1-B12, C, Folate Energy metabolism, collagen, red blood cells
Macro-minerals Ca, P, Mg, Na, K Bone structure, nerve function, fluid balance
Trace minerals Fe, Zn, Cu, Se, I Oxygen transport, immune function, thyroid
from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    # Get micronutrient data for a food
    food = api.get_food("spinach")
    vitamins = food["vitamins"]
    minerals = food["minerals"]
    print(f"Vitamin A: {vitamins['vitamin_a']} mcg RAE")
    print(f"Iron: {minerals['iron']} mg")
    print(f"Calcium: {minerals['calcium']} mg")

Learn more: Nutrients · Guides

Food Comparison

Comparing foods by nutrient density — nutrients per calorie rather than per weight — reveals which foods deliver the most nutritional value. Leafy greens and organ meats top nutrient density rankings, while refined grains and sugars score lowest.

from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    # Compare two foods side by side
    comparison = api.compare("chicken-breast", "tofu")
    print(f"Protein: {comparison['food1']['protein']}g vs {comparison['food2']['protein']}g")
    print(f"Calories: {comparison['food1']['calories']} vs {comparison['food2']['calories']}")

Learn more: Food Comparison · Glossary

Dietary Reference Intakes

Dietary Reference Intakes (DRIs) established by the National Academies provide science-based nutrient intake recommendations. The system includes RDA (Recommended Dietary Allowance), AI (Adequate Intake), UL (Tolerable Upper Intake Level), and EAR (Estimated Average Requirement).

Term Definition Use
RDA Meets needs of 97-98% of population Daily target
AI Used when RDA cannot be determined Estimated target
UL Maximum safe daily intake Upper safety limit
EAR Meets needs of 50% of population Population assessment
from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    # Look up nutrient RDA values
    nutrients = api.list_nutrients()
    for n in nutrients[:5]:
        print(f"{n['name']}: RDA {n['rda']} {n['unit']}")

Learn more: Dietary Guidelines · API Documentation

Command-Line Interface

pip install "nutrifyi[cli]"

nutrifyi food chicken-breast                # Full nutrition profile
nutrifyi search "brown rice"                # Search food database
nutrifyi compare chicken-breast tofu        # Side-by-side comparison
nutrifyi nutrients                          # List all tracked nutrients

MCP Server (Claude, Cursor, Windsurf)

pip install "nutrifyi[mcp]"
{
    "mcpServers": {
        "nutrifyi": {
            "command": "uvx",
            "args": ["--from", "nutrifyi[mcp]", "python", "-m", "nutrifyi.mcp_server"]
        }
    }
}

REST API Client

from nutrifyi.api import NutriFYI

with NutriFYI() as api:
    food = api.get_food("chicken-breast")        # GET /api/v1/foods/chicken-breast/
    nutrients = api.list_nutrients()              # GET /api/v1/nutrients/
    results = api.search("avocado")              # GET /api/v1/search/?q=avocado

Example

curl -s "https://nutrifyi.com/api/v1/foods/chicken-breast/"
{
    "slug": "chicken-breast",
    "name": "Chicken Breast (cooked)",
    "calories": 165,
    "protein": 31.0,
    "fat": 3.6,
    "carbohydrates": 0.0,
    "fiber": 0.0
}

Full API documentation at nutrifyi.com/developers/.

API Reference

Function Description
api.get_food(slug) Full nutrition profile (macros + micros)
api.list_foods() List all foods in database
api.search(query) Search food database
api.compare(food1, food2) Side-by-side nutrient comparison
api.list_nutrients() All tracked nutrients with RDA values
api.get_nutrient(slug) Nutrient details and top food sources

Learn More About Nutrition

Also Available

Platform Install Link
npm npm install nutrifyi npm
MCP uvx --from "nutrifyi[mcp]" python -m nutrifyi.mcp_server Config

Health FYI Family

Part of the FYIPedia open-source developer tools ecosystem — human body, medicine, and nutrition.

Package PyPI npm Description
anatomyfyi PyPI npm 14,692 anatomical structures, body systems, organs — anatomyfyi.com
pillfyi PyPI npm Pill identification, FDA drug database — pillfyi.com
drugfyi PyPI npm Drug interactions, pharmacology, side effects — drugfyi.com
nutrifyi PyPI npm Nutrition data, food composition, dietary analysis — nutrifyi.com

License

MIT

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

nutrifyi-0.1.1.tar.gz (634.8 kB view details)

Uploaded Source

Built Distribution

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

nutrifyi-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nutrifyi-0.1.1.tar.gz
  • Upload date:
  • Size: 634.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nutrifyi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9bc2d8ec58dcd2d2e9bd0285718771dfdb25fa64331477e3e2e15e6c226a3bc8
MD5 bff3c43ac3badc148dd87165512c4c45
BLAKE2b-256 b3111435dfbeb8f0f41eb2e97ad6384468c3629ad4a79b58225667581e76cc05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nutrifyi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nutrifyi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40b9abec7992d33cc1e8fb964acaef3e8eed55c1da50c31a50fa4e0e280f0eca
MD5 3d9276c88457d86d5b8989c747192503
BLAKE2b-256 9ed79cb68db0f1f3a3aae9911efcdc5e9aae2525d3b92dedb7dd307e58c5bb12

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