Skip to main content

Calorie API for Python

The official Python client for Calorie API, the nutrition API for 6.8M+ foods. Search foods, look up barcodes, read full nutrient data, and calculate macro targets, portion nutrition and recipe totals from one small, typed, zero-dependency package.

Python 3.9 or newer. Standard library only (urllib). Fully type hinted, with TypedDict response types.

Install

pip install calorie-api

Quick start

from calorie_api import CalorieApi

api = CalorieApi("your_api_key")

page = api.search_foods("chicken breast", limit=5)
for food in page["data"]:
    print(food["id"], food["name"], food["calories_100g"], "kcal per 100 g")

If you leave out the key, the client reads the CALORIE_API_KEY environment variable. Requests go to https://calorieapiadmin.com/api/v1 with your key in the X-API-Key header.

Endpoints

Method HTTP endpoint
search_foods(query, **filters) GET /api/v1/search/foods
suggest_foods(query, limit=None) GET /api/v1/search/suggest
lookup_barcode(barcode) GET /api/v1/search/barcode/{upc}
get_food(food_id) GET /api/v1/foods/{food_id}
calc_macros(age=, gender=, weight_kg=, height_cm=, activity=, goal=) GET /api/v1/calc/macros
calc_portion(food_id, grams) GET /api/v1/calc/portion
calc_recipe(ingredients, servings=None) POST /api/v1/calc/recipe

Every method returns the parsed JSON response as plain dicts and lists, typed with the TypedDict classes exported from calorie_api (FoodSearchPage, FoodDetails, BarcodeLookupResult, MacroCalcResult and so on). Keyword names match the API parameter names.

Search foods

page = api.search_foods(
    "greek yogurt",
    limit=10,
    skip=0,
    verified_only=True,
    max_calories=120,
)

print(page["total"])
first = page["data"][0]
print(first["name"], first["brand_name"])
print(first["calories_100g"], first["protein_100g"], first["carbs_100g"], first["fat_100g"])
print(first["nutrients"])

Returns {"data", "total", "skip", "limit"}. Each result has per 100 g values (calories_100g, protein_100g, carbs_100g, fat_100g, fiber_100g, sugar_100g), a nutrients list, serving info and a meal dict scaled to the default serving.

Keyword filters:

Keyword Notes
limit 1 to 100, default 30. Your plan caps the results per search.
skip Offset for paging
match_mode "any" (default) or "all" words
verified_only Only verified foods
brand, brand_id Filter by brand
category, category_id Filter by category
nutrient_id, min_amount, max_amount Require a nutrient in a range
min_calories, max_calories Calories per 100 g
min_protein, max_protein Grams per 100 g
min_carbs, max_carbs Grams per 100 g
min_fat, max_fat Grams per 100 g

An empty query ("") returns common foods.

Autocomplete

suggestions = api.suggest_foods("chi", limit=8)
# [{"id": ..., "name": ..., "brand_name": ...}, ...]

Barcode lookup

product = api.lookup_barcode("3017620422003")
print(product["product"]["name"], product["product"]["brand"])
print(product["nutrition_per_100g"]["energy_kcal"], product["nutrition_per_100g"]["protein_g"])
print(product["micronutrients_per_100g"])

UPC and EAN codes are accepted as strings. Spaces and dashes are removed before the request. An unknown barcode raises CalorieApiError with status 404.

Food details

food = api.get_food(first["id"])
print(food["name"], food["nutrients"], food["barcodes"], food.get("verified_portions"))

Macro targets (TDEE)

macros = api.calc_macros(
    age=28,
    gender="male",
    weight_kg=80,
    height_cm=178,
    activity="moderately_active",
    goal="maintain",
)

print(macros["bmr"], macros["tdee"])
print(macros["daily_targets"])
# {"calories", "protein_g", "carbohydrates_g", "fat_g"}

gender is "male" or "female". activity is "sedentary", "lightly_active", "moderately_active", "very_active" or "extra_active". goal is "lose", "maintain" or "gain". The API uses the Mifflin-St Jeor formula.

Portion nutrition

portion = api.calc_portion(first["id"], 150)
print(portion["food_name"], portion["requested_grams"], portion["nutrition"])
# nutrition: calories, protein_g, carbohydrates_g, fat_g, fiber_g, sugars_g, saturated_fat_g, sodium_g

Recipe nutrition

recipe = api.calc_recipe(
    [
        {"food_id": 12345, "grams": 300},
        (67890, 200),
    ],
    servings=4,
)

print(recipe["total"]["calories"], recipe["per_serving"]["calories"], recipe["ingredients_resolved"])

Each ingredient is a dict with food_id and grams, or a (food_id, grams) tuple. Up to 50 ingredients and 1 to 100 servings (default 1). ingredients_resolved counts the ingredients found in the database.

Error handling

Every failure raises CalorieApiError:

from calorie_api import CalorieApi, CalorieApiError

try:
    api.get_food(999999999)
except CalorieApiError as error:
    print(error)              # "Calorie API returned 404: Food not found"
    print(error.status)       # 404, or None when no response arrived
    print(error.kind)         # "http_error"
    print(error.detail)       # the API's "detail" value
    print(error.retry_after)  # seconds to wait, from Retry-After, or None
kind When
http_error The API answered with a non-2xx status. The message includes the status and the API's error message.
timeout No response within timeout seconds
network_error DNS, TLS or connection failure
invalid_response A 2xx response that was not JSON
invalid_argument A bad argument, caught before any request was sent

Common statuses: 401 for a missing or wrong key, 402 when your monthly quota is used up, 403 when your plan does not cover the request, 404 when a food or barcode is not found, 422 for out-of-range parameters (the message lists each field), and 429 when you go over your plan's per-minute rate limit.

Configuration

api = CalorieApi(
    "your_key",
    timeout=10,
    base_url="https://calorieapiadmin.com",
)
Argument Default Notes
api_key CALORIE_API_KEY env var Your Calorie API key
timeout 30.0 Per request timeout in seconds
base_url https://calorieapiadmin.com API origin, without /api/v1. Must be https, except for localhost.
demo False Use the keyless public demo when no key is set

The client never follows redirects, so your key is only sent to the host you configured. It honors the standard HTTPS_PROXY and NO_PROXY environment variables.

Public demo (no key)

demo = CalorieApi(demo=True)
page = demo.search_foods("apple", limit=5)

The demo uses the /api/v1/public/... routes, which are limited to 30 requests per hour per IP address and one request per second, with at most 10 results per search. Use it to try the API, then switch to a free key.

Pricing

The free tier includes 1,000 API calls a month. Paid plans start at $15 a month for 20,000 calls. Each plan also sets a rate limit and a cap on results per search (20 foods per search on the free plan). Commercial apps need the Plus or Enterprise plan. See calorieapi.com/pricing for current plans.

License

MIT. Copyright (c) 2026 BusyBody FIT LTD.

Metadata

Release files for calorie-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calorie-api 0.1.0
File Size Uploaded Provenance Actions
calorie_api-0.1.0.tar.gz 19.6 kB Without provenance Details for calorie_api-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for calorie-api 0.1.0
File Interpreter ABI Platform Actions
calorie_api-0.1.0-py3-none-any.whl Python 3 none any Details for calorie_api-0.1.0-py3-none-any.whl

Total release size: 32.6 kB

Release files / calorie_api-0.1.0.tar.gz

Download URL calorie_api-0.1.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7e5058b971c323fa34348c981ab3ed555175787ea8bc1fa26b0b4dc92e9893c6
BLAKE2b-256 checksum
How to use checksums
c2e079574e31532d6a42fb74e797f5a6c54617324139f0e3d118963c6f7726f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / calorie_api-0.1.0-py3-none-any.whl

Download URL calorie_api-0.1.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c9b2bd30fd776f99f3f692ac5d6c07fd1839263c787172ef3169b9c5705a2af
BLAKE2b-256 checksum
How to use checksums
6bcf2a1af99fa5205cd89b240d5e309fc17656191a0746e998b6359778ebebf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for calorie-api 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page