A Python API for accessing USDA FoodData Central data
Project description
FoodData Central Python API
This package provides a simple, ready-to-use Python API for accessing and querying relevant data from the USDA FoodData Central database—no API key required. All data is processed locally from CSV files and exposed through a clean Python interface.
Installation
You can install the package from PyPI:
pip install pyfooda
Or install directly from the repository:
pip install git+https://github.com/yourusername/pyfooda.git
Features
- No API key required: Works entirely offline with preprocessed FoodData Central CSV files.
- Simple: Query food categories, nutrients, and portion information with a few lines of code.
- Search: Find foods by partial name.
- DataFrames: Access the raw fooddata and DRV DataFrames for custom analysis.
Example
import pyfooda as pf
# Find up to 10 foods matching a partial name
print(pf.find_closest_matches('apple'))
# Get the category of a food
print(pf.get_category('Apple, raw'))
# Get all nutrient values for a food
nutrients = pf.get_nutrients('Apple, raw')
print(nutrients)
# Get portion information
print(pf.get_portion_gram_weight('Apple, raw')) # e.g., 138.0
print(pf.get_portion_unit_name('Apple, raw')) # e.g., "medium"
# Get the raw DataFrames
fooddata_df = pf.get_fooddata_df()
drv_df = pf.get_drv_df()
API Reference
get_category(foodName)
Returns the food category for the given food name (case-insensitive). Returns 'Other' if not found.
get_nutrients(foodName)
Returns a dictionary of nutrient values for the given food name. Returns None if not found.
get_portion_gram_weight(foodName)
Returns the portion gram weight (float) for the given food name. Returns None if not found.
get_portion_unit_name(foodName)
Returns the portion unit name (string) for the given food name. Returns None if not found.
find_closest_matches(partialName)
Returns a list of up to 10 food names that contain the given partial name (case-insensitive).
get_fooddata_df()
Returns the fooddata DataFrame containing all food items and their nutrient values.
get_drv_df()
Returns the DRV (Dietary Reference Values) DataFrame containing nutrient reference values.
License
Test package
pip install -e .
python -c "import pyfooda; print(pyfooda.__version__)"
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfooda-0.1.4.tar.gz.
File metadata
- Download URL: pyfooda-0.1.4.tar.gz
- Upload date:
- Size: 9.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6d30bf0510887654e334fa13bd51c24e3fcdc655d9c4224f0a0aa474dc223f7
|
|
| MD5 |
8367fc626e76d3913f045584d3efdab6
|
|
| BLAKE2b-256 |
7570880a51f671d6dbf7860345df82813d6af7714e42ed24c29bdb679c28b2c6
|
File details
Details for the file pyfooda-0.1.4-py3-none-any.whl.
File metadata
- Download URL: pyfooda-0.1.4-py3-none-any.whl
- Upload date:
- Size: 9.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e76e29b7600deecf7cfe1fbad8165e07531c95bbd81a6d0e236123828de1f8c9
|
|
| MD5 |
59b8a9ab02df3ae7a12be1b26a6ba128
|
|
| BLAKE2b-256 |
b357f9d8d24868baa1a2263446974fd8212da1b492ba85c424c03e952c2abc48
|