PHPackages                             openfoodfacts/openfoodfacts-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. openfoodfacts/openfoodfacts-php

ActiveLibrary[API Development](/categories/api)

openfoodfacts/openfoodfacts-php
===============================

Open Food Facts API Wrapper, the open database about food.

v0.4.0(7mo ago)6942.2k—0%39[11 issues](https://github.com/openfoodfacts/openfoodfacts-php/issues)[8 PRs](https://github.com/openfoodfacts/openfoodfacts-php/pulls)MITPHPPHP ^8.1CI passing

Since Jan 23Pushed 2mo ago16 watchersCompare

[ Source](https://github.com/openfoodfacts/openfoodfacts-php)[ Packagist](https://packagist.org/packages/openfoodfacts/openfoodfacts-php)[ Docs](https://world.openfoodfacts.org/)[ Fund](https://donate.openfoodfacts.org/?utm_source=github&utf_medium=web&utm_campaign=funding_links)[ GitHub Sponsors](https://github.com/openfoodfacts)[ RSS](/packages/openfoodfacts-openfoodfacts-php/feed)WikiDiscussions develop Synced today

READMEChangelog (7)Dependencies (8)Versions (21)Used By (0)

openfoodfacts-php - Official PHP package for Open Food Facts
============================================================

[](#openfoodfacts-php---official-php-package-for-open-food-facts)

   ![](https://camo.githubusercontent.com/f9a0b288f62c3f2d8d87a8d97c58ea61790394a2743a97ce5f622410d7e0f401/68747470733a2f2f7374617469632e6f70656e666f6f6466616374732e6f72672f696d616765732f6c6f676f732f6f66662d6c6f676f2d686f72697a6f6e74616c2d6c696768742e737667)PHP API Wrapper for [Open Food Facts](https://openfoodfacts.org/), the open database about food.

[![Project Status](https://camo.githubusercontent.com/db785e974d50375ffabc7fcb4b08b7458601c081d81e29fa8ce818f6f6d422b4/68747470733a2f2f6f70656e736f757263652e626f782e636f6d2f6261646765732f6163746976652e737667)](https://opensource.box.com/badges)[![Build Status](https://camo.githubusercontent.com/98e05e782729a8c5d828c962d5d878cfb4e9595d0b2009d8915aacc8a84066aa/68747470733a2f2f7472617669732d63692e6f72672f6f70656e666f6f6466616374732f6f70656e666f6f6466616374732d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/openfoodfacts/openfoodfacts-php)[![Average time to resolve an issue](https://camo.githubusercontent.com/f2d01626ce00b77fff87f078022f19bc3e592b031d786fcddff536e181d4d287/68747470733a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f7265736f6c7574696f6e2f6f70656e666f6f6466616374732f6f70656e666f6f6466616374732d7068702e737667)](https://isitmaintained.com/project/openfoodfacts/openfoodfacts-php "Average time to resolve an issue")[![Percentage of issues still open](https://camo.githubusercontent.com/bbc5aa5dfe14a6845bb0e59dc43a71096d0eafb20d35ac119651a685c1fa97a1/68747470733a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f6f70656e2f6f70656e666f6f6466616374732f6f70656e666f6f6466616374732d7068702e737667)](https://isitmaintained.com/project/openfoodfacts/openfoodfacts-php "Percentage of issues still open")

Current features
----------------

[](#current-features)

- Search-A-Licious (#62), user-agent (#53), PHP 8.1 (#47), Image upload
- Most features should be visible here:
- PLEASE DOCUMENT ANY MISSING FEATURES HERE

Installation
------------

[](#installation)

With Composer:

```
composer require openfoodfacts/openfoodfacts-php
```

Usage
-----

[](#usage)

This is the most basic way of creating the API:

```
$api = new OpenFoodFacts\Api('food','fr');
$product = $api->getProduct('3057640385148');
```

In the example above you access the "food" database, limited to the French language/country scope. The first parameter is either

- "food"
- "beauty" or
- "pet"

to decide which product database you want to use.

The second parameter decides the language/country scope of the chosen database: f.e. "world" or "de" or "fr".

For more details on this topic: see the [API Documentation](https://en.wiki.openfoodfacts.org/API/Read#Countries_and_Language_of_the_Response)

These are all the parameters you really need for basic usage.

As return types for `$api->getProduct` you get an `Document::class` Object. This may also be an Object of Type `FoodProduct::class`,`PetProduct::class`, `BeautyProduct::class` depending on which API you are creating. These objects inherit from the more generic `Document::class`

In the example above, we use the 'food' API and there will get a `FoodProduct::class`

For getting a first overview the `Document::class` has a function to return an array representation(sorted) for a first start.

```
$product = $api->getProduct('3057640385148');
$productDataAsArray = $product->getData();
```

#### Optional Parameters

[](#optional-parameters)

The other parameters are optional and for a more sophisticated use of the api (from a software development point of view):

An example in code is found here: [cached\_example.php](examples/01-basic_api_usage/cached_example.php)

LoggerInterface: A logger which decieds where to log errors to (file, console , etc)

see: [PSR-3 Loggerinterface](https://www.php-fig.org/psr/psr-3/)

ClientInterface: The HTTP Client - to adjust the connection configs to your needs and more

see: [Guzzle HTTP Client](https://packagist.org/packages/guzzlehttp/guzzle)

CacheInterface: To temporarily save the results of API request to improve the performance and to reduce the load on the API- Server

see: [PSR-16 Simple Cache](https://www.php-fig.org/psr/psr-16/)

Development
-----------

[](#development)

### Contributing

[](#contributing)

1. Fork it (  )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Launch test `vendor/bin/phpunit` &amp;&amp; cs-fixer `vendor/bin/php-cs-fixer fix`
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create a new Pull Request

Using this SDK and Third party applications
-------------------------------------------

[](#using-this-sdk-and-third-party-applications)

- If you use this SDK, feel free to open a PR to add your application in the list in [REUSERS.md](https://github.com/openfoodfacts/openfoodfacts-php/blob/develop/REUSERS.md)
- Make sure you comply with the OdBL licence, mentioning the Source of your data, and ensuring to avoid combining non free data you can't release legally as open data. Another requirement is contributing back any product you add using this SDK.
- Please get in touch at
- We are very interested in learning what the Open Food Facts data is used for. It is not mandatory, but we would very much appreciate it if you tell us about your re-uses () so that we can share them with the Open Food Facts community. You can also fill this form to get a chance to get your app featured:

Authors
-------

[](#authors)

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~297 days

Recently: every ~495 days

Total

9

Last Release

235d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.1

v0.3.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/04ae98a418754a2b7859ec3db6d9a37c07dcf2b3034e6ff5ad93c5cee027b5ea?d=identicon)[openfoodfacts](/maintainers/openfoodfacts)

![](https://www.gravatar.com/avatar/fc20d45ce6787b30545f3b570bc0eb8721ab54f81d4647ce6d4bed2b4f598a66?d=identicon)[epalmans](/maintainers/epalmans)

![](https://www.gravatar.com/avatar/a7b4bf2c9cf2e03861229cc196d46f4171f41c84e33d132e41bd70052f47e0fd?d=identicon)[rampmaster](/maintainers/rampmaster)

---

Top Contributors

[![Dwarfex](https://avatars.githubusercontent.com/u/721721?v=4)](https://github.com/Dwarfex "Dwarfex (52 commits)")[![epalmans](https://avatars.githubusercontent.com/u/7260915?v=4)](https://github.com/epalmans "epalmans (33 commits)")[![teolemon](https://avatars.githubusercontent.com/u/1689815?v=4)](https://github.com/teolemon "teolemon (31 commits)")[![Benoit382](https://avatars.githubusercontent.com/u/5646257?v=4)](https://github.com/Benoit382 "Benoit382 (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![rampmaster](https://avatars.githubusercontent.com/u/978024?v=4)](https://github.com/rampmaster "rampmaster (5 commits)")[![deepsource-autofix[bot]](https://avatars.githubusercontent.com/in/57168?v=4)](https://github.com/deepsource-autofix[bot] "deepsource-autofix[bot] (4 commits)")[![jordan-temim](https://avatars.githubusercontent.com/u/82808982?v=4)](https://github.com/jordan-temim "jordan-temim (4 commits)")[![sebrave](https://avatars.githubusercontent.com/u/15705705?v=4)](https://github.com/sebrave "sebrave (2 commits)")[![rmoreno-as](https://avatars.githubusercontent.com/u/44907174?v=4)](https://github.com/rmoreno-as "rmoreno-as (2 commits)")[![tazorax](https://avatars.githubusercontent.com/u/1062894?v=4)](https://github.com/tazorax "tazorax (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")[![mikaelcom](https://avatars.githubusercontent.com/u/584391?v=4)](https://github.com/mikaelcom "mikaelcom (2 commits)")[![nicolasleger](https://avatars.githubusercontent.com/u/570901?v=4)](https://github.com/nicolasleger "nicolasleger (1 commits)")[![deepsourcebot](https://avatars.githubusercontent.com/u/60907429?v=4)](https://github.com/deepsourcebot "deepsourcebot (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

foodhacktoberfestphpphp-wrapper

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/openfoodfacts-openfoodfacts-php/health.svg)

```
[![Health](https://phpackages.com/badges/openfoodfacts-openfoodfacts-php/health.svg)](https://phpackages.com/packages/openfoodfacts-openfoodfacts-php)
```

###  Alternatives

[duncan3dc/sonos

Control Sonos speakers using a simple API

10915.1k](/packages/duncan3dc-sonos)[commercetools/commercetools-sdk

The official PHP SDK for the commercetools Composable Commerce APIs

19273.0k](/packages/commercetools-commercetools-sdk)[dtyq/php-mcp

PHP implementation of MCP server and client

278.3k1](/packages/dtyq-php-mcp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
