Skip to main content

ingredient-slicer

Python 📦 package for extracting quantities, units, and food words from unstructured recipe ingredients text.

ingredient-slicer works by standardizing the input text and then applying a set of rules and heuristic methods to parse out quantities, units, and food words from unstructured recipe ingredients text. ingredient-slicer was designed to provide a robust and lightweight method for parsing recipe ingredients text without relying on any external dependencies or NLP/ML models. That being said, it is not perfect and can always be improved upon.

Table of Contents:


Installation:

ingredient_slicer can be downloaded from PyPI via pip like so:

pip install ingredient-slicer

Usage:

Provide a string to the IngredientSlicer class and thats it. Invoke the to_json() method to return the parsed ingredient.

import ingredient_slicer

slicer = ingredient_slicer.IngredientSlicer("2 (15-ounces) cans chickpeas, rinsed and drained")

slicer.to_json()

{   
    'ingredient': '2 (15-ounces) cans chickpeas, rinsed and drained', 
    'standardized_ingredient': '2 cans chickpeas, rinsed and drained', 
    'food': 'chickpeas', 

    # primary quantity and units
    'quantity': '30', 
    'unit': 'ounces', 
    'standardized_unit': 'ounce', 

    # any other secondary quantity and units found in the string
    'secondary_quantity': '2', 
    'secondary_unit': 'cans', 
    'standardized_secondary_unit': 'can', 

    'gram_weight': '850.49', 
    'prep': ['drained', 'rinsed'], 
    'size_modifiers': [], 
    'dimensions': [], 
    'is_required': True, 
    'parenthesis_content': ['15 ounce']
}

Individual ingredient components can also be found using methods like food(), quantity(), or unit()

import ingredient_slicer

slicer = ingredient_slicer.IngredientSlicer("3 tbsp unsalted butter, softened at room temperature")

slicer.food() 
>>> 'unsalted butter'

slicer.quantity() 
>>> '3' 

slicer.unit() 
>>> 'tbsp'

slicer.standardized_unit() 
>>> 'tablespoon'

slicer.prep() 
>>> ['room temperature', 'softened']

Contributing/Issues:

If you find a bug or have an idea for a new feature, please open an issue or submit a pull request :)

Metadata

Release files for ingredient-slicer 1.2.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ingredient-slicer 1.2.21
File Size Uploaded
ingredient_slicer-1.2.21.tar.gz 126.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ingredient-slicer 1.2.21
File Interpreter ABI Platform
ingredient_slicer-1.2.21-py3-none-any.whl Python 3 none any Details

Total release size: 209.5 kB

Release files / ingredient_slicer-1.2.21.tar.gz

Download URL ingredient_slicer-1.2.21.tar.gz
Size 126.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cfcd40a4af0ee9f2d82ce4639aa8fefb041a5e931eaca7f491d6043033779843
BLAKE2b-256 checksum
How to use checksums
97679df9a1981525af8afdb8cf53960afc00a4a069deaad983c4d60786ae3a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / ingredient_slicer-1.2.21-py3-none-any.whl

Download URL ingredient_slicer-1.2.21-py3-none-any.whl
Size 82.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2bcbeafd7ac69dc23e40e0d771bee5754ee711689eb4db09d93523e212ad0ce
BLAKE2b-256 checksum
How to use checksums
53db9b080f908a6ee94e39ddd3bc1a94fcf6182a7e669656eea39750a83fa20f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.2.21 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.1.15

2 release files

1.1.14

2 release files

1.1.13

2 release files

1.1.12

2 release files

1.1.11

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.88

2 release files

0.0.87

2 release files

0.0.81

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

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