Skip to main content

Official Python SDK of Open Food Facts

Project description

Open Food Facts Python SDK

Open Food Facts

Status

Project Status Build Status codecov Latest Version License: MIT

Description

This is the official Python SDK for the Open Food Facts project. It provides a simple interface to the Open Food Facts API and allows you to:

  • Get information about a product
  • Perform text search
  • Create a new product or update an existing one

It also provides some helper functions to make it easier to work with Open Food Facts data and APIs, such as:

  • getting translation of a taxonomized field in a given language
  • downloading and iterating over the Open Food Facts data dump
  • handling OCRs of Open Food Facts images generated by Google Cloud Vision

Please note that this SDK is still in beta and the API is subject to change. Make sure to pin the version in your requirements file.

Installation

The easiest way to install the SDK is through pip:

pip install openfoodfacts

or manually from source:

git clone https://github.com/openfoodfacts/openfoodfacts-python
cd openfoodfacts-python
python setup.py install

Examples

All the examples below assume that you have imported the SDK and instanciated the API object:

import openfoodfacts

# User-Agent is mandatory
api = openfoodfacts.API(user_agent="MyAwesomeApp/1.0")

Get information about a product

code = "3017620422003"
api.product.get(code, fields=["code", "product_name"])
# {'code': '3017620422003', 'product_name': 'Nutella'}

Perform text search

api.product.text_search("mineral water")
# {"count": 3006628, "page": 1, "page_count": 20, "page_size": 20, "products": [{...}], "skip": 0}

Create a new product or update an existing one

results = api.product.update({
    "code": CODE,
    "product_name_en": "blueberry jam",
    "ingredients_text_en": "blueberries, sugar, pectin, citric acid"
})

with CODE the product barcode. The rest of the body should be a dictionary of fields to create/update.

To see all possible capabilities, check out the usage guide.

Third party applications

If you use this SDK, feel free to open a PR to add your application in this list.

Contributing

Any help is welcome, as long as you don't break the continuous integration. Fork the repository and open a Pull Request directly on the "develop" branch. A maintainer will review and integrate your changes.

Maintainers:

Contributors:

Copyright and License

Copyright 2016-2024 Open Food Facts

The Open Food Facts Python SDK is licensed under the 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

openfoodfacts-2.2.0.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

openfoodfacts-2.2.0-py3-none-any.whl (48.3 kB view details)

Uploaded Python 3

File details

Details for the file openfoodfacts-2.2.0.tar.gz.

File metadata

  • Download URL: openfoodfacts-2.2.0.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for openfoodfacts-2.2.0.tar.gz
Algorithm Hash digest
SHA256 e79ec1292238078de5e4857a19a7ccc66ca99b766311a9d7e60e9bf5315ac762
MD5 1d1afbca7a9d89f4a94fa61885e687bb
BLAKE2b-256 768c376fc0ae1ee2abd2f7b4726474fe58b9725f0e368cfd390aa312738be6c1

See more details on using hashes here.

File details

Details for the file openfoodfacts-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: openfoodfacts-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 48.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.20 Linux/6.5.0-1025-azure

File hashes

Hashes for openfoodfacts-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 172c953fd5727ffbe23bd2839afebc15cc346c3e186976e98b3d37026a90ba5b
MD5 f70fb52659031fe22b676d26e3df445f
BLAKE2b-256 7888ff3197960a9f587e29578ea62697edae4a499e950c8641b20944f2ca1099

See more details on using hashes here.

Supported by

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