Skip to main content

No project description provided

Project description

py-fdc

A python interface to interact with the USDA's FoodDataCentral API

Features

  • An object oritented interface for FoodDataCentral's

Requirements

  • Python >=3.10

Dependencies

Development Dependencies

Installation

The simplest way to install it is to pip install it.

pip install py-usda-fdc

To install the development version you can pip the git version.

pip install git+https://github.com/ghostiek/py-fdc.git

Getting Started

Get an API Key

An API Key is necessary to make calls to USDA's API. You can get one by filling in this form.

# Import the FDC module
from fdc.fdc import FDC

# Initialize the client with your API key
client = FDC(api_key)

Getting the Serialized output from the API

# Get Food using FDCId
food = client.get_food(fdc_id) # Returns a Food object

# Get multiple Foods using a list of FDCIds
foods = client.get_foods([fdc_id1, fdc_id2, fdc_id3]) # Returns a list of Food objects

# Get a paged list of foods
food_list = client.get_foods_list() # Returns a list of AbridgedFood

# Search foods using keywords, in this case, get 200 cheese items
cheeses = client.get_foods_search("cheese") # Returns a SearchResult object

Getting the Raw JSON as a string

Unfortunately, the USDA's FoodDataCentral API can be quite inconsistent at times, I've tried mapping it the best I could but if it results in an error, you can always just get the json string using the raw parameter Here is the equivalent of the functions referenced previously, except the output is a string.

# All of them are strings
food_raw = client.get_food_raw(fdc_id)
foods_raw = client.get_foods_raw([fdc_id1, fdc_id2, fdc_id3])
food_list_raw = client.get_foods_list_raw()
cheeses_raw = client.get_foods_search_raw("cheese")

API Documentation

More information about the API is available here

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

py_usda_fdc-0.2.0.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

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

py_usda_fdc-0.2.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file py_usda_fdc-0.2.0.tar.gz.

File metadata

  • Download URL: py_usda_fdc-0.2.0.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for py_usda_fdc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d40e2d697ed6365c3d4310bfeefcc20f00c2db6b696ff1fb91242a8924c11f39
MD5 14e006970f7d101082ad74943e1e45d0
BLAKE2b-256 b78bad0ab6edf75d38d6dbbfcc03c8bc431f32c34bc4b6c25093e2d3f1902d80

See more details on using hashes here.

File details

Details for the file py_usda_fdc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: py_usda_fdc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for py_usda_fdc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 334a95e861830644ba95815360143450d1a40fee6a6817f99821edc78b770b2a
MD5 0ca7d91b9a840812d0f2b7df2eb8caa8
BLAKE2b-256 8533183ce29780c632f1266098d301d0ec02f71942367bf7928fcf2e6806b950

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