A small Python project for querying the FruityVice API and returning fruit details in either human-readable or machine-readable format.
- Fetches fruit data from the FruityVice REST API.
- Supports CLI usage and library usage.
- Returns name, id, family, sugar, and carbohydrates.
- Human-readable output includes gram units for gram-based nutrition fields.
- Handles unknown fruits and unavailable API responses gracefully.
- Includes automated tests for API logic, formatting, CLI behavior, and integration paths.
- Python 3.11+
- Network access to https://www.fruityvice.com/api/fruit/all
From the project root:
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .Run as a module:
python -m fruit_lookup.cli Banana --format human
python -m fruit_lookup.cli Banana --format jsonOr via installed script:
fruit-cli Banana --format human- Required:
fruit_name - Optional:
--formatwith valueshumanorjson(optional as the default is:human)
- Empty names are rejected.
- Invalid names (numbers/symbols) are rejected.
- Names must contain letters, spaces, hyphens, or apostrophes only.
from fruit_lookup import lookup_fruit
result = lookup_fruit(
search_params={"name": "Banana"},
output_params=["name", "id", "family", "sugar", "carbohydrates"],
output_format="json",
)
print(result)- Human format: multi-line labels (for example,
Sugar: 12.2 g). - JSON format: machine-readable JSON string.
- Unknown fruit name raises and reports
FruitNotFoundError. - API/network/invalid-response issues raise and report
APIUnavailableError. - Invalid CLI usage exits cleanly with argparse usage feedback.
pytest -q
src/
fruit_lookup/
api.py
cli.py
exceptions.py
formatter.py
library.py
tests/
test_api.py
test_cli.py
test_formatter.py
test_integration.py
- Create a focused branch.
- Add or update tests for behavior changes.
- Run formatting and test checks locally.
- Open a pull request with a concise summary and rationale.
No license file is currently included. Add a LICENSE file before public distribution.