Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ print(results)
# 'vegetarian': 'yes'}]
```

## Barcode utilities

The SDK includes utilities for normalizing and validating barcodes (GTINs):

```python
from openfoodfacts.barcode import normalize_barcode, has_valid_check_digit

# Normalize a barcode (pad to 8 or 13 digits)
normalize_barcode("3017620422003") # '3017620422003'
normalize_barcode("4003") # '00004003' (padded to 8)

# Validate a barcode check digit
has_valid_check_digit("3017620422003") # True
has_valid_check_digit("3017620422004") # False
```

## Working with other Open*Facts projects

The SDK supports all Open*Facts projects, not just food:

```python
from openfoodfacts import API, Flavor

# Open Beauty Facts
beauty_api = API(user_agent="<app>", flavor=Flavor.obf)
product = beauty_api.product.get("3600523577941")

# Open Pet Food Facts
petfood_api = API(user_agent="<app>", flavor=Flavor.opff)

# Open Products Facts
products_api = API(user_agent="<app>", flavor=Flavor.opf)
```

## Using the dataset

If you're planning to perform data analysis on Open Food Facts, the easiest way is to download and use the Open Food Facts dataset dump. Fortunately it can be done really easily using the SDK:
Expand Down
Loading