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.

Third party applications

If you use this SDK or want to use this SDK, make sure to read the REUSE and ensure you comply with the OdBL licence, in addition to the licence of this package (MIT). Make sure you at least fill the form, and feel free to open a PR to add your application in this list :-)

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
pip install .  # Note the “.” at the end!

Examples

All the examples below assume that you have imported the SDK and instantiated 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.

Contributing

See CONTRIBUTING.md

Copyright and License

Copyright 2016-2024 Open Food Facts

The Open Food Facts Python SDK is licensed under the MIT License.

Other files that are not part of the SDK itself may be under different a different license. The project complies with the REUSE 3.3 specification, so any such files should be marked accordingly.

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-5.1.0.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

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

openfoodfacts-5.1.0-py3-none-any.whl (63.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openfoodfacts-5.1.0.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openfoodfacts-5.1.0.tar.gz
Algorithm Hash digest
SHA256 b263273db42de3d4845512ceea0303d2a57241975531bd9098c8079787c91180
MD5 3c8b7b3f0fff3b6a95662c4a796bb6d1
BLAKE2b-256 4cfdbae21aa405c72935b6a294d0c66b4cc18988a3145e14edde50f9ab58351f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: openfoodfacts-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 63.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openfoodfacts-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb6596d32ee73bce11a7c5d14cb2c3c90829fdf563ac6063db7927d3362a496
MD5 b04b7611a7f8ddb18e306f0ed37f72b4
BLAKE2b-256 c734a6f1b079174d43d5cc52f94f2ee81f124f9532b455ce08f64ee1269e7549

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