Skip to main content

Avocavo Python SDK - Structured nutrition data API with USDA-based calculations, ingredient normalization, and consistent nutrition estimates for apps and workflows.

Project description

🥑 Avocavo Python SDK

Structured nutrition data API with USDA-based calculations where applicable. Consistent nutrition estimates for apps and workflows.

🚀 Quick Start

import avocavo

# Login to your account (OAuth flow)
avocavo.login()

# Analyze a single ingredient
result = avocavo.analyze("1 cup brown rice")
print(f"Calories: {result.nutrition.calories}")

# Analyze a recipe
recipe = avocavo.analyze_recipe([
    "2 large eggs",
    "1 cup all-purpose flour", 
    "1/2 cup milk"
])
print(f"Total calories: {recipe.total_nutrition.calories}")

📦 Installation

pip install avocavo

Requirements:

  • Python >= 3.8
  • Internet connection for API access

🔐 Authentication

  1. Sign up at nutrition.avocavo.app
  2. Login via Python:
    import avocavo
    avocavo.login()  # Opens browser for secure OAuth
    
  3. Your credentials are stored securely in your system keyring

📖 Basic Usage

Single Ingredient Analysis

import avocavo

# Simple ingredient analysis
result = avocavo.analyze("1 cup quinoa, cooked")

print(f"Calories: {result.nutrition.calories}")
print(f"Protein: {result.nutrition.protein}g")
print(f"Fiber: {result.nutrition.fiber}g")

# Access USDA match information
print(f"USDA Food: {result.usda_match.description}")
print(f"Confidence: {result.usda_match.confidence_score}")

Recipe Analysis

# Analyze a complete recipe
ingredients = [
    "2 cups rolled oats",
    "1 banana, mashed", 
    "1/2 cup blueberries",
    "1 cup almond milk"
]

recipe = avocavo.analyze_recipe(ingredients)

# Get totals
print(f"Total Calories: {recipe.total_nutrition.calories}")
print(f"Total Protein: {recipe.total_nutrition.protein}g")

# Get per-serving (if servings specified)
print(f"Per Serving: {recipe.per_serving_nutrition.calories} calories")

# Individual ingredient breakdown
for ingredient in recipe.ingredients:
    print(f"{ingredient.original_input}: {ingredient.nutrition.calories} cal")

Batch Analysis

# Analyze multiple ingredients efficiently
ingredients = [
    "1 cup rice",
    "100g chicken breast",
    "1 medium apple",
    "2 tbsp olive oil"
]

results = avocavo.analyze_batch(ingredients)

for result in results:
    print(f"{result.original_input}: {result.nutrition.calories} calories")

🔧 Advanced Usage

Using the Client Class

from avocavo import NutritionAPI

# Initialize client (uses stored credentials)
client = NutritionAPI()

# Analyze with additional options
result = client.analyze_ingredient(
    "1 cup rice", 
    include_sub_nutrients=True,
    portion_precision="high"
)

# Get detailed nutrition breakdown
nutrients = result.nutrition.detailed_nutrients
for nutrient in nutrients:
    print(f"{nutrient.name}: {nutrient.amount}{nutrient.unit}")

Account Management

import avocavo

# Check your usage
usage = avocavo.get_account_usage()
print(f"Requests used: {usage.requests_used}/{usage.requests_limit}")

# Get current user info
user = avocavo.get_current_user()
print(f"Logged in as: {user.email}")

# Manage API keys
api_keys = avocavo.list_api_keys()
for key in api_keys:
    print(f"Key: {key.name} (Created: {key.created_at})")

🔒 Security Features

  • 🔐 Secure Authentication: OAuth flow with system keyring storage
  • 🛡️ SSL Verification: All API calls use secured HTTPS connections
  • 🔑 No Hardcoded Secrets: Credentials stored securely, never in code
  • 🚫 Input Sanitization: All inputs properly validated and sanitized

📊 Data Models

Nutrition Object

nutrition = result.nutrition

# Macronutrients
print(nutrition.calories)      # kcal
print(nutrition.protein)       # grams
print(nutrition.carbs)         # grams  
print(nutrition.fat)           # grams
print(nutrition.fiber)         # grams

# Micronutrients
print(nutrition.sodium)        # mg
print(nutrition.calcium)       # mg
print(nutrition.iron)          # mg
print(nutrition.vitamin_c)     # mg

USDA Match Information

match = result.usda_match

print(match.fdc_id)           # USDA FDC ID
print(match.description)      # Food description
print(match.confidence_score) # Match confidence (0-1)
print(match.data_type)        # SR Legacy, Foundation, etc.

🚨 Error Handling

from avocavo import ApiError

try:
    result = avocavo.analyze("invalid ingredient")
except ApiError as e:
    print(f"API Error: {e.message}")
    print(f"Status Code: {e.status_code}")
    
    if e.status_code == 401:
        print("Authentication required - run avocavo.login()")
    elif e.status_code == 429:
        print("Rate limit exceeded - upgrade your plan")

📚 Examples

Meal Planning

import avocavo

# Plan a day of meals
breakfast = avocavo.analyze_recipe([
    "2 eggs, scrambled",
    "1 slice whole wheat toast",
    "1/2 avocado"
])

lunch = avocavo.analyze_recipe([
    "4 oz grilled chicken",
    "1 cup quinoa",
    "1 cup steamed broccoli"
])

dinner = avocavo.analyze_recipe([
    "6 oz salmon fillet",
    "1 cup brown rice", 
    "1 cup roasted vegetables"
])

# Calculate daily totals
daily_calories = (breakfast.total_nutrition.calories + 
                 lunch.total_nutrition.calories + 
                 dinner.total_nutrition.calories)

print(f"Daily Total: {daily_calories} calories")

Recipe Scaling

# Original recipe for 4 servings
original = avocavo.analyze_recipe([
    "2 cups flour",
    "4 eggs",
    "1 cup milk"
], servings=4)

# Scale to 8 servings (double)
scale_factor = 8 / 4

scaled_ingredients = []
for ingredient in original.ingredients:
    # Extract amount and scale (simplified example)
    scaled_amount = ingredient.parsed_amount * scale_factor
    scaled_ingredients.append(f"{scaled_amount} {ingredient.parsed_unit} {ingredient.parsed_food}")

scaled_recipe = avocavo.analyze_recipe(scaled_ingredients, servings=8)

🆘 Support

📄 License

MIT License - see LICENSE file for details.


🔄 Migrating from avocavo-nutrition?

The old package has been deprecated due to security vulnerabilities. Migration is straightforward:

# Remove old package
pip uninstall avocavo-nutrition

# Install new secure package
pip install avocavo

Code changes:

# OLD (deprecated)
import avocavo_nutrition as av
av.login()

# NEW (secure)
import avocavo
avocavo.login()

All functionality remains the same - only the import and security have been improved!

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

avocavo-1.2.1.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

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

avocavo-1.2.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file avocavo-1.2.1.tar.gz.

File metadata

  • Download URL: avocavo-1.2.1.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for avocavo-1.2.1.tar.gz
Algorithm Hash digest
SHA256 59dfe3e05f8ee5dbd1f7c215c15ccfc56d19d69343d9510f510ebef84a7bce9f
MD5 2a3b09a0a5043f6da5b64ed8cc1d1406
BLAKE2b-256 8f4fa900397ca7e26ca8121a89882729f8c0ca672f73a48141f5b4c60628c951

See more details on using hashes here.

File details

Details for the file avocavo-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: avocavo-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for avocavo-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7588efd3b7aca5b3d4cc40b96d642add919071ee1bc25c6f9a4b5d98328d1f5b
MD5 7666eb18838e89da6909097faf211702
BLAKE2b-256 7ddf8691134fe50c0ea9a617710df21239cfb9cf1b748468a0bed0c01255ef54

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