Food Composition Tables (FCTables)¶
A food composition table (FCT) describes a dataset of foods and their nutrient
content — its provenance, coverage, units, and the schemes it follows. FCTables are
URN-backed (urn:fctable:<slug>) and reached through client.fctables.
What it is¶
Entity class |
|
Collection |
|
Endpoint |
|
Identifier |
URN ( |
Quick example¶
import os
from wisefood import DataClient, Credentials
client = DataClient(
os.environ["WISEFOOD_API_URL"],
Credentials(username=os.environ["WISEFOOD_USERNAME"],
password=os.environ["WISEFOOD_PASSWORD"]),
)
fct = client.fctables["national-fct-2020"]
print(fct.title, "·", fct.compiling_institution)
print(f"{fct.number_of_entries} entries, {fct.completeness_percent}% complete")
Field reference¶
Field |
Type |
Notes |
|---|---|---|
|
|
Read-only. |
|
|
|
|
|
|
|
|
Defaults to |
|
|
Defaults to |
|
|
Who produced the table. |
|
|
|
|
|
e.g. food grouping schemes. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Which nutrients are covered. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read-only. |
CRUD walkthrough¶
# Create
fct = client.fctables.create(
title="National Food Composition Table 2020",
compiling_institution="National Nutrition Institute",
database_name="NFCT-2020",
measurement_units=["g", "mg", "kcal"],
number_of_entries=1850,
)
# Update — auto-syncs
fct.completeness_percent = 92.5
fct.nutrient_coverage = ["energy", "protein", "fat", "carbohydrate", "iron"]
# Batch
fct.sync = False
fct.classification_schemes = ["FoodEx2"]
fct.data_formats = ["csv", "json"]
fct.save(only_dirty=True)
# Delete
fct.delete()
Search¶
hits = client.fctables.search("micronutrients", limit=10)
for t in hits:
print(t.title, "—", t.number_of_entries, "entries")
See Search for all parameters.
Attached files¶
The underlying dataset files (CSV, spreadsheets, source PDFs) are attached as artifacts:
fct.artifacts.upload("nfct-2020.csv", title="Full dataset (CSV)")
for a in fct.artifacts:
print(a.title, a.file_size)
See Artifacts.
Gotchas¶
id,creator,created_at,updated_atare read-only.List-typed fields (
measurement_units,nutrient_coverage, …) default to empty lists; reassign the whole list to change them.