• Stars
    star
    162
  • Rank 232,284 (Top 5 %)
  • Language
    Dart
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Open Food Facts API Wrapper

Open Food Facts - Dart

Pub Version Run sdk tests likes popularity pub points

Dart package for the Open Food Facts API. Free and Easy access to more than 2.9 million food products information from all around the world. Open Food Facts is powered by contributors from around the world and is constantly growing thanks to them.

General principles, how does it work ?

We use the ability of the Open Food Facts API to return products results in JSON, we then generate easily understandable objects structures to make it simple for you to use.

This plugin also allows you to edit a product or upload a new one to Open Food Facts. Using the same simple product structure you can create a product object or edit an existing one and send it to the API using a single function.

Migrating from 1.x.x to 2.x.x (breaking changes)

  • Now the only entry point is import 'package:openfoodfacts/openfoodfacts.dart';
    • replace all your instances of import 'package:openfoodfacts/...'; with a single import 'package:openfoodfacts/openfoodfacts.dart';
  • If you used State from product_state.dart, you have to rename it to ProductState
  • If you used Level from nutrient_levels.dart, you have to rename it to NutrientLevel
  • Removed deprecated classes:
    • Page
    • ProductListQueryConfiguration
    • ToBeCompletedConfiguration
  • Removed deprecated fields and methods in Nutriments
    • all the single nutrient value fields were removed - use getValue and setValue instead
    • instead of getUnit use nutrient.typicalUnit

Usage

Installation

Follow the installing instructions on pub.dev.

How to authenticate

For most queries no authentication is required! :) Though we recommend to set a User-Agent to not to be blocked by mistake.

Setup (Optional)

At the beginning of the app you can define some global settings so that they don't need to be specified in each query. You can override these static values at any time in the app lifecycle.

import 'package:openfoodfacts/openfoodfacts.dart';

OpenFoodAPIConfiguration.userAgent = UserAgent(name: 'Your app name', url: 'Your url, if applicable');

OpenFoodAPIConfiguration.globalLanguages = <OpenFoodFactsLanguage>[
  OpenFoodFactsLanguage.ENGLISH
];

OpenFoodAPIConfiguration.globalCountry = OpenFoodFactsCountry.FRANCE;

All possible configurations can be found here.

Features

Code examples for the following tasks:

Reading data

Writing data

Robotoff support

Robotoff it the Open Food Facts AI which analyze every new pictures to extract new data.

Folksonomy Engine

Folksonomy is adding several kinds of new individual data properties to Open Food Facts or Open Products Facts.

Contributing data

Handle Open Food Facts accounts

Some queries which modify or enter data need a user account to validate this request. There are multiple ways to handle user accounts:

  1. Let your users login / create Open Food Facts user accounts (Recommended)
  2. Create a global user for your app through which all requests run

Currently there is no OAuth workflow, therefor a user is just a User object in this package. So you need to get the username as well as the password from the users and store it somewhere save. For Flutter apps we recommend using the flutter_secure_storage package

For the user to be taken into account you have mount a global user at one point in your app lifecycle:

  OpenFoodAPIConfiguration.globalUser = User(
    userId: 'myUsername',
    password: 'myPassword',
  );

Regardless if you are using a global app or accounts per user. After mounting this, the user will be added to queries where the user can be attributed.

Some methods in OpenFoodAPIClient require to pass a User, there you can access the before mounted user with:

 OpenFoodAPIClient.thisNeedsAnUser(
  user: OpenFoodAPIConfiguration.globalUser,
  ...
 );

Further examples:

If your users do not expect a specific result immediately (eg. Inventory apps)

  • Send photos (front/nutrition/ingredients/packaging): most painless thing for your users
  • The Open Food Facts AI Robotoff will generate some derived data from the photos
  • Overtime, other apps, and the Open Food Facts community will fill the data gaps

If your users do expect a result immediately (eg Nutrition apps, Scoring apps…)

  • Send nutrition facts + category > get the Nutri-Score
  • Send ingredients > get the NOVA group (about food ultra-processing), additives, allergens, normalized ingredients, vegan, vegetarian…
  • Send category (strict minimum) + labels + origins of ingredients + packaging (photo and text) > get the Eco-Score (about environmental impact)

Open Data License

The database in under the OdBL. This means attributing the source and also contributing back any additions (photos, data), which this package makes easy to do. You can check the terms of use here : Terms of use.

Useful recourses

Contribute to the package

If found a bug or missing features in this package, please open an issue for it.

  • Issue Tracker: github.com/openfoodfacts/openfoodfacts-dart/issues
  • Source Code: github.com/openfoodfacts/openfoodfacts-dart

Support

If you are having issues, that go beyond the scope of this package, please write to us on Slack or send us an email at [email protected]

Testing

Execute the following command from the root of the repository to run the tests:

dart test

Applications using this SDK

Official application

Open Food Facts (Codename Smoothie) is the official app developed by Open Food Facts, which is available on Android and iOS. The source code is also available on GitHub.

Third party applications

Feel free to open a PR to add your application in this list.

Authors

Thanks to Alexander Schacht and PrimaΓ«l QuΓ©merais for the initial creation of this package.

Contributors

Drag Racing

More Repositories

1

smooth-app

The new Open Food Facts mobile application for Android and iOS, crafted with Flutter and Dart
Dart
773
star
2

openfoodfacts-androidapp

(Legacy) Native version of Open Food Facts on Android - Coders & Decoders welcome 🀳πŸ₯«
Kotlin
771
star
3

openfoodfacts-server

Open Food Facts database, API server and web interface - πŸͺπŸ¦‹ Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
HTML
652
star
4

openfoodfacts-ios

Native (Swift) version of Open Food Facts for iOS. Coders & Decoders welcome 🀳πŸ₯« 😊
Swift
359
star
5

openfoodfacts-python

Python package for Open Food Facts
Python
308
star
6

openfoodfacts-ai

This is a tracking repo for all our AI projects. πŸ• πŸ€–πŸΌ
Python
213
star
7

off-nutrition-table-extractor

Important: Please have a look at the higher level issue in Robotoff: openfoodfacts/robotoff#372 This is an old model and we have made progress since then.
Jupyter Notebook
204
star
8

openfoodfacts-laravel

Open Food Facts API wrapper for Laravel
PHP
150
star
9

openfoodfacts-nodejs

Official Node package for Open Food Facts
TypeScript
143
star
10

openfoodfacts-cordova-app-old-with-blob

Open Food Facts App in Cordova (Android)
JavaScript
83
star
11

robotoff

Real-time and batch prediction service for Open Food Facts
Python
72
star
12

openfoodfacts-php

PHP wrapper for Open Food Facts
PHP
57
star
13

openfoodfacts-apirestpython

Python API for Open Food Facts (using a DB dump)
Python
53
star
14

openfoodfacts-go

Go Wrapper for Open Food Facts
Go
51
star
15

openfoodfacts-react-native

Code to send product data and photos to Open Food Facts
JavaScript
40
star
16

openbeautyfacts

Meta project for Open Beauty Facts πŸ’„
36
star
17

open-prices

An open database of prices πŸ§ΎπŸ’ΈπŸ’°πŸ·οΈπŸ€‘πŸ½οΈ
Python
36
star
18

openfoodfacts-ruby

Open Food Facts API Wrapper
Ruby
33
star
19

openfoodfacts-cordova-app

Open Food Facts mobile app, developed with Cordova, for iOS, Android, Windows Phone, FirefoxOS etc.
JavaScript
28
star
20

open-prices-frontend

A vue.js front-end for Open Prices
Vue
25
star
21

hunger-games

One click Mini-Games for Open Food Facts
TypeScript
23
star
22

api-documentation

Version 2 of the documentation of the V1 API. The code behind the API is at https://github.com/openfoodfacts/openfoodfacts-server. An effort is made there to create a V3 of the documentation based on OpenAPI
19
star
23

openfoodfacts-web

Content pages (and translations) for the web version
HTML
16
star
24

taxonomy-editor

Taxonomies are at the heart of Open Food Facts data structure - this project provides an editor
Python
15
star
25

openfoodfacts-kotlin

Official Kotlin package for Open Food Facts
Kotlin
12
star
26

openfoodfacts-java

Java Wrapper for OpenFoodFacts
Java
12
star
27

power-user-script

User script for your browser, to empower Open Food Facts contribution
JavaScript
11
star
28

rate-my-recipe

A project allowing you to get the Nutri-Score, Eco-Score…on your own food recipe
TypeScript
11
star
29

folksonomy_api

A light REST API designed for Open Food Facts folksonomy engine
Python
11
star
30

openfoodfacts-hungergames

One click Mini-Games for Open Food Facts for: categories, labels, weight, brands, logos… We'd need to port and improve nutrition and ingredients from the old version.
Vue
9
star
31

eu-food-data

This repository aggregates food packaging codes available about European countries, and foreign countries trading with the EU.
HTML
9
star
32

openbeautyfacts-ruby

Open Beauty Facts API Wrapper πŸ’ŽπŸ’„
Ruby
8
star
33

search-a-licious

πŸŠπŸ”Ž A pluggable search service for large collections of objects (like Open Food Facts)
Python
8
star
34

off-category-classification

Jupyter Notebook
8
star
35

openfoodfacts-ubuntu

Open Food Facts project for Ubuntu Touch
QML
7
star
36

openfoodfacts-events

Events repository and API for product scans, photo uploads, robotoff annotations etc.
Python
7
star
37

community-portal

A community portal for Open Food Facts contributors
Python
6
star
38

openfoodfacts-resources

Resources (images, SVGs, presentations etc.) for the Open Food Facts project
CSS
6
star
39

facets-knowledge-panels

Providing knowledge panels for a particular open food fact facet (category, brand, etc...)
Python
6
star
40

openfoodfacts-explorer

An alternative frontend for OpenFoodFacts, made with SvelteKit
Svelte
5
star
41

openfoodfacts-hungergames-react

One click categorizer for Open Food Facts
JavaScript
5
star
42

openfoodfacts-design

5
star
43

impactestimator

Service providing product level Eco-Score for OFF products.
Python
4
star
44

ruby-games

Games to complete data on Open Food Facts
Ruby
4
star
45

openfoodfacts-elixir

Elixir
4
star
46

robotoff-models

Models for Robotoff, the Open Food Facts AI
4
star
47

openfoodfacts-rust

Rust SDK package
Rust
4
star
48

openfoodfacts-translations

Translations for the Open Food Facts blog. Most of the other folders are being moved elsewhere.
HTML
4
star
49

hungergames-old

Gamification of Open Food Facts using Python and Django
Python
4
star
50

openfoodfacts-java-demo

Demo application using Java Wrapper for OpenFoodFacts
Java
3
star
51

off-product-environmental-impact

A fork of https://framagit.org/GustaveCoste/off-product-environmental-impact
Jupyter Notebook
3
star
52

recipe-estimator

A recipe estimator for Open Food Facts products
Python
3
star
53

www

Repository for phonegapbuild
JavaScript
3
star
54

openfoodfacts-moodstocks

Open Food Facts app with Moodstocks scanner
Java
2
star
55

openbeautyfacts-cordova-app

JavaScript
2
star
56

fastlane-descriptions-smoothie

Automation of the Play Store and App Store listings for Smoothie with Fastlane
Ruby
2
star
57

r-dashboard

R
2
star
58

openfoodfacts-upptime

πŸ“ˆ Uptime monitor and status page for Open Food Facts, powered by @upptime
Markdown
2
star
59

egg-codes

Repository for Egg Codes
2
star
60

folksonomy_engine

2
star
61

nutripatrol

A moderation tool for Open Food Facts
Python
2
star
62

contributor-quality-issues

Report data quality issues due to contributing apps/users
1
star
63

openfoodfacts-metrics

1
star
64

openfoodfacts-connect

1
star
65

openfoodfacts-infrastructure

Where we collaboratively plan and maintain the infrastructure of Open Food Facts
Shell
1
star
66

openfoodfacts-marketing

1
star
67

openfoodfacts-csharp

C#
1
star
68

msc-codes

List of MSC Codes for Open Food Facts
1
star
69

fastlane-descriptions

JavaScript
1
star
70

folksonomy_frontend

Folksonomy Engine front end
JavaScript
1
star
71

brand-data

1
star
72

openfoodfacts-monitoring

Makefile
1
star
73

openfoodfacts-build-cache

A repo to store some build caches (when github cache is not the right option)
1
star
74

openfoodfacts-corrector

Ruby script to correct and enhance data on OpenFoodFacts
Ruby
1
star
75

openfoodfacts_flutter_lints

Lints for OpenFoodFacts Flutter apps & packages
Dart
1
star
76

openproductsfacts

1
star
77

openfoodfacts-ffos

Repo for the Firefox OS port of Open Food Facts
JavaScript
1
star
78

.github

A repository for default files such as style guides, issue templates, etc.
1
star
79

openfoodfacts-swift

Swift
1
star
80

nutripatrol-frontend

The front-end (React) of nutripatrol moderation tool
TypeScript
1
star
81

recipe-estimator-metrics

Metrics framework for recipe estimation (estimating percentage of each ingredient)
Python
1
star