Skip to main content

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

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfooda-0.1.0.tar.gz (32.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfooda-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pyfooda-0.1.0.tar.gz.

File metadata

  • Download URL: pyfooda-0.1.0.tar.gz
  • Upload date:
  • Size: 32.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pyfooda-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d9ba141679b6fcb164a19728f282cc3243966a8847aac607b504a3ffc52f0c62
MD5 eeb9ec33600ca3d8ca3f1be51114f50c
BLAKE2b-256 ac30a5246e2e90ace8f74147e340831501b1777c9cdc6a6045b98e8768d118bf

See more details on using hashes here.

File details

Details for the file pyfooda-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyfooda-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pyfooda-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f329fcb78894096dd2abef315f6d7851ad7d5f8371266ee6291c467a0e1450b5
MD5 f9a111b1a241185268d67e65e6f446b5
BLAKE2b-256 a23b728f26fe338d4ae106f0e43f2ce49289fde456c11e8675145341e6b1b89b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page