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

The package is not on PyPI yet. Install it from this repo:

pip install "nutriscan @ git+https://github.com/NutriScan-App/food-recognition-nutrition-api#subdirectory=packages/python"

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 food search or barcode endpoint: to look up one food, send it as text with an amount. Optional context hints (meal_time, cooking_method and others) are listed under create a scan.

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.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 nutriscan 0.1.0
File Size Uploaded Provenance Actions
nutriscan-0.1.0.tar.gz 7.1 kB With provenance Details for nutriscan-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 12.9 kB

Release files / nutriscan-0.1.0.tar.gz

Download URL nutriscan-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72f68c6642dbc62ce34c9d05dd7cf867a0e912359b9fa0ec99475a3835c0c55e
BLAKE2b-256 checksum
How to use checksums
f5e8fad027bab31a1eec8783f02c10be7667161096e5409023ef35408ac74fab
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 Nov 30, 2026.

Transparency log

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

Download URL nutriscan-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc06d726d55d7e7c2e12d4d3b4e5210064a13bb0c462480c2c352596ae2476c4
BLAKE2b-256 checksum
How to use checksums
c0fa94debf0abb9f6382f6a977945ddf413490814ecfaecf66d6a7a58ade689e
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 Nov 30, 2026.

Transparency log

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

Full provenance

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

Select from 2 files

Attestation for nutriscan-0.1.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 Nov 30, 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.1.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