Skip to content

SamBradley2024/Fruityvice-Python-Package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fruit Lookup CLI + Library

A small Python project for querying the FruityVice API and returning fruit details in either human-readable or machine-readable format.

Features

  • 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.

Requirements

Installation

From the project root:

python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .

CLI Usage

Run as a module:

python -m fruit_lookup.cli Banana --format human
python -m fruit_lookup.cli Banana --format json

Or via installed script:

fruit-cli Banana --format human

CLI Arguments

  • Required: fruit_name
  • Optional: --format with values human or json (optional as the default is: human)

Input validation

  • Empty names are rejected.
  • Invalid names (numbers/symbols) are rejected.
  • Names must contain letters, spaces, hyphens, or apostrophes only.

Library Usage

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)

Output Behavior

  • Human format: multi-line labels (for example, Sugar: 12.2 g).
  • JSON format: machine-readable JSON string.

Error Handling

  • 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.

Development

Run tests

pytest -q

Project Structure

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

Contributing

  1. Create a focused branch.
  2. Add or update tests for behavior changes.
  3. Run formatting and test checks locally.
  4. Open a pull request with a concise summary and rationale.

License

No license file is currently included. Add a LICENSE file before public distribution.

About

Project for the coding assignment for RSE Placement at University of Manchester

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages