Skip to main content

nutriscan: Python client for the NutriScan food recognition and nutrition API

Send a meal photo, a photo of a pack's nutrition label, or a text description, and get back calories, macros, micronutrients and a NutriScore for each item. One module, standard library only, Python 3.9 and later.

Install

pip install nutriscan

Every new account at platform.nutriscan.app comes with a free test key (ns_test_...). It returns one fixed sample result and uses no credits, so you can build against it before you buy prepaid credits for a live key (ns_live_...).

Quickstart

from nutriscan import NutriScan

client = NutriScan()  # reads NUTRISCAN_KEY, or pass NutriScan("ns_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
result = client.scan("https://nutriscan.app/images/api/grilled-chicken-grain-plate.webp")

meal = result["meal"]
print(meal["name"], "| NutriScore", meal["nutri_score"])
print(meal["totals"]["calories"], "kcal,", meal["totals"]["protein_g"], "g protein")
for item in result["items"]:
    print("-", item["name"], item["portion"]["display"], item["calories"], "kcal")

Output with a test key, which always returns this fixed sample:

Grilled chicken with rice and salad | NutriScore B
515.0 kcal, 51.9 g protein
- Grilled chicken breast 150 g 248.0 kcal
- Steamed white rice 1 cup (158 g) 205.0 kcal
- Green salad with olive oil 80 g 62.0 kcal

Results come back as plain dicts with the JSON fields described on the result page. Read micros by key, since new nutrients can appear. The numbers are estimates for food logging, not medical advice.

The three inputs

client.scan("lunch.jpg")                                   # meal photo from a file path
client.scan(photo_bytes, type="label", language="fr")       # nutrition label, raw bytes
client.scan(text="200 g low-fat quark with blueberries")    # text, type "text" is set for you

An image can be a file path, bytes, or an https:// URL. Paths and bytes go up as image_base64, URLs as image_url. type defaults to meal for images. There is no barcode endpoint. Optional context hints (meal_time, cooking_method and others) are listed under create a scan.

found = client.search_foods("apple", limit=5, country="US")   # 3 credits with a live key
for food in found["results"]:
    print(food["id"], food["name"], food["per_100g"]["calories"], "kcal per 100 g")

food = client.get_food("fd_test_apple")                        # 1 credit with a live key
print(food["serving"]["label"], food["per_serving"]["calories"], "kcal")

The key needs the search scope; keys made before December 1, 2026 are scan only and raise NutriScanError with code scope_missing. A nutrient that is not known is None, never 0. A test key is free and knows three sample foods (Masala Dosa, Paneer Tikka, Apple). Fields are on the food search page.

Streaming

for event in client.stream("https://nutriscan.app/images/api/grilled-chicken-grain-plate.webp"):
    if event["event"] == "items.detected":
        print("Items:", [i["name"] for i in event["data"]["items"]])
    elif event["event"] == "scan.completed":
        print(event["data"]["meal"]["totals"]["calories"], "kcal")

Each event is {"event": name, "data": parsed JSON}. Keep the id from scan.started: if the connection drops, client.get_scan(id) returns the finished scan.

Errors and retries

Every non-2xx answer, and an error event in a stream, raises NutriScanError with .status, .code, .message and .retry_after.

from nutriscan import NutriScanError

try:
    client.scan("empty-table.jpg")
except NutriScanError as e:
    print(e.status, e.code, e.message)  # 422 no_food_detected ...

The client retries 429, 500, 503 and 409 idempotency_in_progress up to max_retries times (default 2), plus dropped connections. It waits for Retry-After when the API sends one, never more than 60 seconds. Each scan sends an Idempotency-Key (yours, or a fresh UUID) and reuses it on retries, so a retry uses credits once. The HTTP timeout is 100 seconds, because a scan can take up to 95.

client.usage() returns your credit numbers.

Docs

MIT licensed.

Metadata

Release files for nutriscan 0.2.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 nutriscan 0.2.0
File Size Uploaded Provenance Actions
nutriscan-0.2.0.tar.gz 7.7 kB With provenance Details for nutriscan-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nutriscan 0.2.0
File Interpreter ABI Platform Actions
nutriscan-0.2.0-py3-none-any.whl Python 3 none any Details for nutriscan-0.2.0-py3-none-any.whl

Total release size: 13.9 kB

Release files / nutriscan-0.2.0.tar.gz

Download URL nutriscan-0.2.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1dca307a152952aa8aed29af28b988b81039e3ab54b79f5d6c91aa7b4ebb4054
BLAKE2b-256 checksum
How to use checksums
bde314eacf7a57085455d4414ea24833cc9bbc0df80106a3712aefedd4a40c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / nutriscan-0.2.0-py3-none-any.whl

Download URL nutriscan-0.2.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
252e21846bdc52bc483101137d2c130686452bc1e393940ee2756ee8248eee89
BLAKE2b-256 checksum
How to use checksums
81076f21fff197f82bd6bc86ec8553f0bc4f4a4d29d6250801c8bd6d2c634b18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for nutriscan 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nutriscan-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

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.2.0 This release

2 release files Full 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