### List and Get Equipment Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Provides examples for listing all equipment with descriptions and retrieving equipment by ID or name. ```python # List all equipment for e in grocy.equipment.list(get_details=True): print(f"{e.name}: {e.description}") # Get by ID or name e = grocy.equipment.get(equipment_id=1) e = grocy.equipment.get_by_name("Coffee machine") ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Install project dependencies for development using uv sync with the dev group. ```bash # Install dependencies uv sync --group dev ``` -------------------------------- ### Install grocy-py Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Install the grocy-py library using pip. ```bash pip install grocy-py ``` -------------------------------- ### Barcode Operations Examples Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Provides commented-out examples for various stock operations using product barcodes. These include lookup, adding, consuming, opening, transferring, and inventory adjustments. ```python # Barcode operations # product = grocy.stock.product_by_barcode("1234567890") # grocy.stock.add_by_barcode("1234567890", amount=1, price=1.0) # grocy.stock.consume_by_barcode("1234567890", amount=1) # grocy.stock.open_by_barcode("1234567890", amount=1) # grocy.stock.transfer_by_barcode("1234567890", amount=1, location_from=1, location_to=2) # grocy.stock.inventory_by_barcode("1234567890", new_amount=5) # grocy.stock.barcode_lookup("1234567890") ``` -------------------------------- ### Initialize Grocy Client Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Initialize the Grocy client with the base URL and API key. Use this for basic setup. ```python from grocy import Grocy grocy = Grocy("https://example.com", "GROCY_API_KEY") ``` -------------------------------- ### Get System Configuration Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieve the grocy system's configuration settings, such as operational mode, currency, locale, and enabled features. This helps understand the grocy instance's setup. ```python # Get system config config = grocy.system.config() if config: print(f"Mode: {config.mode}") print(f"Currency: {config.currency}") print(f"Locale: {config.locale}") print(f"Enabled features: {config.enabled_features}") ``` -------------------------------- ### List and Execute Chores Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/chores.md Demonstrates how to list chores with details and execute a specific chore. Ensure you have the grocy-py library installed and initialized. ```python for chore in grocy.chores.list(get_details=True): print(f"{chore.name} - next: {chore.next_estimated_execution_time}") grocy.chores.execute(chore_id=1, done_by=1) ``` -------------------------------- ### List and Manage Chores Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Shows how to list chores, get details, execute them, and undo executions. Assumes grocy-py is set up. ```python # List all chores chores = grocy.chores.list(get_details=True) for chore in chores: print(f"{chore.name} - next: {chore.next_estimated_execution_time}") # Get specific chore details chore = grocy.chores.get(chore_id=1) # Execute a chore grocy.chores.execute(chore_id=1, done_by=1) # Undo an execution grocy.chores.undo(execution_id=1) # Calculate next assignments grocy.chores.calculate_next_assignments() ``` -------------------------------- ### Get Grocy System Information Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieves system-level details such as Grocy version, operating system, server time (UTC and timezone), and configuration settings like currency and enabled features. Also shows how to get the last database change time. ```python # System information info = grocy.system.info() print(f"Grocy {info.grocy_version} on {info.os}") # Server time time = grocy.system.time() print(f"UTC: {time.time_utc}, Timezone: {time.timezone}") # Configuration config = grocy.system.config() print(f"Currency: {config.currency}, Features: {config.enabled_features}") # Last database change db_time = grocy.system.db_changed_time() ``` -------------------------------- ### Get Recipe Details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates how to retrieve a specific recipe by its ID and display its name and base servings. ```python # Get a recipe recipe = grocy.recipes.get(recipe_id=1) print(f"{recipe.name} ({recipe.base_servings} servings)") ``` -------------------------------- ### System Information Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieves system-level information about the Grocy installation, including version, OS, server time, and configuration details. ```APIDOC ## System Operations ### Description Provides methods to retrieve information about the Grocy system and its configuration. ### Methods - `grocy.system.info()`: Returns general system information, including Grocy version and OS. - `grocy.system.time()`: Returns the current server time in UTC and the configured timezone. - `grocy.system.config()`: Returns the Grocy system configuration, including currency and enabled features. - `grocy.system.db_changed_time()`: Returns the timestamp of the last database change. ### Response Fields - `grocy.system.info()`: `grocy_version` (str), `os` (str) - `grocy.system.time()`: `time_utc` (str), `timezone` (str) - `grocy.system.config()`: `currency` (str), `enabled_features` (list) ``` -------------------------------- ### List and Get Batteries Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates how to list all batteries with details and retrieve a specific battery by its ID. ```python # List batteries batteries = grocy.batteries.list(get_details=True) for battery in batteries: print(f"{battery.name}: last charged {battery.last_charged}") # Get a specific battery battery = grocy.batteries.get(battery_id=1) ``` -------------------------------- ### List and Manage Tasks Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Provides examples for listing tasks, retrieving specific task details, and marking tasks as complete or undoing completion. Assumes grocy-py is initialized. ```python # List tasks tasks = grocy.tasks.list() for task in tasks: print(f"{task.name} - due: {task.due_date}") # Get a specific task task = grocy.tasks.get(task_id=1) # Complete / undo grocy.tasks.complete(task_id=1) grocy.tasks.undo(task_id=1) ``` -------------------------------- ### Quick Example: Grocy Client Initialization and Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/index.md Demonstrates how to initialize the Grocy client and perform common operations such as retrieving current stock, identifying overdue products, and managing the shopping list. Ensure you replace placeholder URLs and API keys with your actual Grocy instance details. ```Python from grocy import Grocy grocy = Grocy("https://your-grocy-instance.com", "YOUR_API_KEY") # Get current stock for product in grocy.stock.current(): print(f"{product.name}: {product.available_amount} in stock") # Get overdue products for product in grocy.stock.overdue_products(): print(f"{product.name} is overdue!") # Manage shopping list shopping_list = grocy.shopping_list.items(get_details=True) for item in shopping_list: print(f"{item.product.name}: {item.amount}") ``` -------------------------------- ### Start Local Docker Instance Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Launch a local Grocy demo instance using Docker Compose for immediate experimentation. This sets up Grocy on localhost:9192 with a pre-defined API key. ```bash docker compose up -d ``` -------------------------------- ### Get Meal Plan Sections Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates how to retrieve all meal plan sections and a specific section by its ID. ```python # Get meal plan sections sections = grocy.meal_plan.sections() section = grocy.meal_plan.section(section_id=1) ``` -------------------------------- ### Stock Booking and Transaction Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Shows commented-out examples for managing stock bookings and transactions. Includes retrieving and undoing operations by their IDs. ```python # Stock booking / transaction operations # booking = grocy.stock.booking(booking_id=1) # grocy.stock.undo_booking(booking_id=1) # transactions = grocy.stock.transaction(transaction_id="abc") # grocy.stock.undo_transaction(transaction_id="abc") ``` -------------------------------- ### Get Stock Entries for a Product Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves all individual stock entries associated with a specific product. This allows for detailed tracking of each addition or consumption event. ```python # Get stock entries for a product entries = grocy.stock.product_entries(product_id=1) for entry in entries: print( f" Entry {entry.id}: amount={entry.amount}, best_before={entry.best_before_date}" ) ``` -------------------------------- ### Manage Grocy Users Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates how to get the current user, list all users, retrieve a specific user, and perform create, edit, and delete operations. Also shows how to manage user-specific settings. ```python # Current user me = grocy.users.current() print(f"Logged in as: {me.username}") # List all users for user in grocy.users.list(): print(f"{user.id}: {user.username}") # Get a specific user user = grocy.users.get(user_id=1) # Create / edit / delete grocy.users.create({"username": "newuser", "password": "secret"}) grocy.users.edit(user_id=2, data={"first_name": "Updated"}) grocy.users.delete(user_id=2) # User settings settings = grocy.users.settings() grocy.users.set_setting("my_key", "my_value") value = grocy.users.get_setting("my_key") grocy.users.delete_setting("my_key") ``` -------------------------------- ### Get All Recipes' Fulfillment Status Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Iterates through all recipes to display their fulfillment status. ```python # Get all recipes' fulfillment status for f in grocy.recipes.all_fulfillment(): print(f"Recipe {f.recipe_id}: fulfilled={f.need_fulfilled}") ``` -------------------------------- ### Get All Products Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches all products defined in the Grocy system, irrespective of their current stock levels. This provides a comprehensive list of all managed items. ```python # Get all products defined in the system (regardless of stock) for product in grocy.stock.all_products(): print(f"{product.id}: {product.name}") ``` -------------------------------- ### Get Grocy System Information Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/system.md Retrieve and print the Grocy version and server time. Access the System Manager via `grocy.system`. ```python info = grocy.system.info() print(f"Grocy {info.grocy_version}") time = grocy.system.time() print(f"Server time: {time.time_utc}") ``` -------------------------------- ### Get Meal Plan Items Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieves and displays items from the meal plan, including recipes or notes. ```python # Get meal plan items meals = grocy.meal_plan.items(get_details=True) for meal in meals: print(f"{meal.day}: {meal.recipe.name if meal.recipe else meal.note}") ``` -------------------------------- ### Get all equipment objects Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves all equipment objects from grocy, including their IDs and names. This is useful for inventorying available equipment. ```python # Get all equipment objects with full details all_equip = grocy.equipment.get_all_objects() for e in all_equip: print(f"{e.id}: {e.name}") ``` -------------------------------- ### Get Price History for a Product Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves the historical pricing data for a product. This allows for analysis of price fluctuations over time. ```python # Get price history for a product prices = grocy.stock.product_price_history(product_id=1) for p in prices: print(f" {p.date}: {p.price}") ``` -------------------------------- ### Get Product Stock Details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieve detailed stock entries, location information, and price history for a specific product. Requires the product ID. ```python # Stock entries, locations, and price history for a product entries = grocy.stock.product_entries(product_id=1) locations = grocy.stock.product_locations(product_id=1) prices = grocy.stock.product_price_history(product_id=1) ``` -------------------------------- ### Tasks Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Manage tasks, including listing all tasks, getting specific task details, and completing or undoing tasks. ```APIDOC ## Tasks ### List tasks ```python tasks = grocy.tasks.list() for task in tasks: print(f"{task.name} - due: {task.due_date}") ``` ### Get a specific task ```python task = grocy.tasks.get(task_id=1) ``` ### Complete / undo ```python grocy.tasks.complete(task_id=1) grocy.tasks.undo(task_id=1) ``` ``` -------------------------------- ### Get Product Groups Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieve a list of all product groups defined in Grocy. This helps in organizing and categorizing products. ```python # Product groups groups = grocy.stock.product_groups() ``` -------------------------------- ### Get, Set, and Delete User Settings Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Manage user-specific settings in grocy. Use get_setting to retrieve a value, set_setting to update or create one, and delete_setting to remove it. ```python # Get / set / delete a user setting # grocy.users.get_setting("some_key") # grocy.users.set_setting("some_key", "some_value") # grocy.users.delete_setting("some_key") ``` -------------------------------- ### Get Recipe Details and Check Fulfillment Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/recipes.md Retrieve a recipe's details and check if its ingredients are fulfilled. Missing ingredients can be added to the shopping list. ```python recipe = grocy.recipes.get(recipe_id=1) print(f"{recipe.name}: {recipe.base_servings} servings") # Check what's missing fulfillment = grocy.recipes.fulfillment(recipe_id=1) print(f"Fulfilled: {fulfillment.need_fulfilled}") # Add missing ingredients to shopping list grocy.recipes.add_not_fulfilled_to_shopping_list(recipe_id=1) ``` -------------------------------- ### Get Stock Status Filters Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Retrieve lists of products that are due, overdue, expired, or missing. Use `get_details=True` for more comprehensive information. ```python # Products that are due, overdue, expired, or missing due = grocy.stock.due_products(get_details=True) overdue = grocy.stock.overdue_products(get_details=True) expired = grocy.stock.expired_products(get_details=True) missing = grocy.stock.missing_products(get_details=True) ``` -------------------------------- ### Get All User Settings Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves all configurable settings for the current user. This can be used to inspect or modify user preferences. The output is a dictionary containing various setting keys and their values. ```python # User settings settings = grocy.users.settings() print(settings) ``` -------------------------------- ### Get System Information Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieve detailed information about the grocy system, including versions of grocy, PHP, SQLite, and the operating system. This is useful for diagnostics and compatibility checks. ```python # Get system info info = grocy.system.info() if info: print(f"Grocy {info.grocy_version} (released {info.grocy_release_date})") print(f"PHP {info.php_version}, SQLite {info.sqlite_version}") print(f"OS: {info.os}") ``` -------------------------------- ### Get specific equipment by ID Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches and prints the name and description of a specific equipment item using its ID. Use this to retrieve details for a single piece of equipment. ```python # Get specific equipment by ID e = grocy.equipment.get(equipment_id=1) if e: print(f"{e.name}: {e.description}") ``` -------------------------------- ### Get Stock Entries by Location Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves stock entries for a specific location. Requires the grocy instance to be initialized and locations to exist. ```python # Get stock entries by location locations = grocy.generic.list(EntityType.LOCATIONS) if locations: loc_id = locations[0]["id"] entries = grocy.stock.entries_by_location(location_id=loc_id) for entry in entries: print(f" Product {entry.product_id}: {entry.amount}") ``` -------------------------------- ### Perform CRUD Operations on Grocy Entities Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/generic.md Demonstrates how to list, get, create, update, and delete entities using the GenericEntityManager. Ensure you import EntityType from grocy.data_models.generic. ```python from grocy.data_models.generic import EntityType # List, get, create, update, delete locations = grocy.generic.list(EntityType.LOCATIONS) loc = grocy.generic.get(EntityType.LOCATIONS, object_id=2) grocy.generic.create(EntityType.LOCATIONS, {"name": "Pantry"}) grocy.generic.update(EntityType.LOCATIONS, object_id=2, data={"name": "Updated"}) grocy.generic.delete(EntityType.LOCATIONS, object_id=2) ``` -------------------------------- ### Get Shopping List Items with Details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves all items from the shopping list, including product details if available. Displays the item name, amount, and completion status. ```python # Get shopping list items items = grocy.shopping_list.items(get_details=True) for item in items: name = item.product.name if item.product else item.note print(f"{name}: {item.amount} (done: {item.done})") ``` -------------------------------- ### Get Specific Product by ID Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves details for a single product using its unique ID. It displays the product name, available amount, and any associated barcodes. ```python # Get a specific product by ID product = grocy.stock.product(1) if product: print(f"{product.name}: {product.available_amount} (barcodes: {product.barcodes})") ``` -------------------------------- ### Get iCal Data and Sharing Link Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/calendar.md Retrieve the iCalendar data for Grocy and generate a sharing link. Ensure you have initialized the grocy object. ```python # Get iCal data ical = grocy.calendar.ical() print(ical) # Get a sharing link link = grocy.calendar.sharing_link() print(f"Share: {link}") ``` -------------------------------- ### Get a specific task Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves a single task by its ID and prints its name and description. Use this when you need to access details of a particular task. ```python # Get a specific task task = grocy.tasks.get(task_id=1) print(f"{task.name}: {task.description}") ``` -------------------------------- ### Get a specific recipe by ID Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches a single recipe by its ID and displays its name, base servings, and picture URL if available. This is useful for detailed recipe lookups. ```python # Get a specific recipe recipe = grocy.recipes.get(recipe_id=1) if recipe: print(f"{recipe.name}: {recipe.base_servings} servings") if recipe.picture_file_name: print(f" Picture URL: {recipe.get_picture_url_path()}") ``` -------------------------------- ### Perform Generic CRUD Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Use these methods to list, get, create, update, and delete Grocy entities. Custom user fields can also be managed. ```python from grocy.data_models.generic import EntityType # List all objects of a type locations = grocy.generic.list(EntityType.LOCATIONS) # Get a single object location = grocy.generic.get(EntityType.LOCATIONS, object_id=2) # Create grocy.generic.create(EntityType.LOCATIONS, {"name": "Pantry"}) # Update grocy.generic.update(EntityType.LOCATIONS, object_id=2, data={"name": "Kitchen Pantry"}) # Delete grocy.generic.delete(EntityType.LOCATIONS, object_id=2) # Custom user fields fields = grocy.generic.get_userfields("products", object_id=1) grocy.generic.set_userfields("products", object_id=1, key="my_field", value="value") ``` -------------------------------- ### Build and Serve Documentation Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Build and serve the project documentation locally using mkdocs serve. ```bash # Build docs uv run mkdocs serve ``` -------------------------------- ### Chores Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Manage chores, including listing all chores, getting specific chore details, executing chores, undoing executions, and calculating next assignments. ```APIDOC ## Chores ### List all chores ```python chores = grocy.chores.list(get_details=True) for chore in chores: print(f"{chore.name} - next: {chore.next_estimated_execution_time}") ``` ### Get specific chore details ```python chore = grocy.chores.get(chore_id=1) ``` ### Execute a chore ```python grocy.chores.execute(chore_id=1, done_by=1) ``` ### Undo an execution ```python grocy.chores.undo(execution_id=1) ``` ### Calculate next assignments ```python grocy.chores.calculate_next_assignments() ``` ``` -------------------------------- ### Get Stock Locations for a Product Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Lists all locations where a specific product is currently stored, along with the amount present at each location. This helps in understanding product distribution within the Grocy system. ```python # Get stock locations for a product locations = grocy.stock.product_locations(product_id=1) for loc in locations: print(f" Location {loc.location_id}: {loc.amount}") ``` -------------------------------- ### Get Calendar Data in iCalendar Format Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetch the grocy calendar data formatted as an iCalendar string. This allows integration with other calendar applications or services. ```python # Get calendar in iCalendar format ical = grocy.calendar.ical() if ical: # Print first 500 chars print(ical[:500]) ``` -------------------------------- ### Get Current Stock Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Retrieve and print the current stock levels for all products. This snippet iterates through the stock and displays product names and available amounts. ```python for product in grocy.stock.current(): print(f"{product.name}: {product.available_amount} in stock") ``` -------------------------------- ### Get meal plan items with details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches all meal plan items, including details about associated recipes or notes. This helps in planning meals and understanding their types (recipe, note, product). ```python # Get meal plan items meals = grocy.meal_plan.items(get_details=True) for meal in meals: name = meal.recipe.name if meal.recipe else meal.note print(f"{meal.day}: {name} (type: {meal.type})") ``` -------------------------------- ### Manage Userfields (Custom Fields) in Grocy Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Demonstrates how to get and set user-defined fields (custom fields) for Grocy objects. This allows for extending entity data with custom information. ```python # Userfields (custom fields on any entity) # fields = grocy.generic.get_userfields("products", object_id=1) # print(fields) # grocy.generic.set_userfields("products", object_id=1, key="my_field", value="my_value") ``` -------------------------------- ### Get System Time Information Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetch the current time details from the grocy system, including the configured timezone, local time, and UTC time. Useful for time-sensitive operations or logging. ```python # Get system time time = grocy.system.time() if time: print(f"Timezone: {time.timezone}") print(f"Local: {time.time_local}") print(f"UTC: {time.time_utc}") ``` -------------------------------- ### Get Specific Chore Details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches detailed information for a single chore, identified by its ID. Includes details like period type and tracking count. ```python # Get specific chore details chore = grocy.chores.get(chore_id=1) print(f"{chore.name}: period={chore.period_type}, track_count={chore.track_count}") ``` -------------------------------- ### Initialize Grocy Client Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Establishes a connection to the Grocy instance using its base URL, API key, and port. Ensure the Grocy instance is running before executing. ```python from grocy import Grocy from grocy.data_models.generic import EntityType grocy = Grocy(base_url="http://localhost", api_key="test_local_devenv", port=9192) ``` -------------------------------- ### Get Sharing Link Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/calendar.md Generates a sharing link for the Grocy calendar. ```APIDOC ## Get Sharing Link ### Description Generates a sharing link for the Grocy calendar. ### Method `grocy.calendar.sharing_link()` ### Parameters None ### Response Example ``` Share: https://your-grocy-instance.com/calendar/ical/your-sharing-token ``` ``` -------------------------------- ### Get iCal Data Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/calendar.md Retrieves the calendar data in iCalendar format. ```APIDOC ## Get iCal Data ### Description Retrieves the calendar data in iCalendar format. ### Method `grocy.calendar.ical()` ### Parameters None ### Response Example ``` BEGIN:VCALENDAR VERSION:2.0 PRODID:-//Grocy//Calendar//EN ... END:VCALENDAR ``` ``` -------------------------------- ### Initialize Grocy Client Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/grocy.md Instantiate the Grocy client by providing your grocy instance URL and API key. This is the first step to interacting with the grocy API. ```python from grocy import Grocy grocy = Grocy("https://your-grocy-instance.com", "YOUR_API_KEY") ``` -------------------------------- ### Get meal plan sections Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves all defined meal plan sections, displaying their IDs, names, and sort order. This is useful for understanding the structure of the meal plan. ```python # Get meal plan sections sections = grocy.meal_plan.sections() for s in sections: print(f"{s.id}: {s.name} (sort: {s.sort_number})") ``` -------------------------------- ### Batteries API Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Provides methods to list, get, charge, and undo battery charge cycles. ```APIDOC ## Batteries API ### Description Provides methods to list all batteries, get details of a specific battery, and manage charging information. ### Methods - `list(get_details: bool)`: Lists batteries. If `get_details` is True, includes detailed information. - `get(battery_id: int)`: Retrieves a specific battery by its ID. - `charge(battery_id: int)`: Marks a battery as charged. - `undo(charge_cycle_id: int)`: Undoes a battery charge cycle using its ID. ``` -------------------------------- ### Get Stock Status (Due, Overdue, Expired, Missing) Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Categorizes and lists products based on their stock status: due, overdue, expired, or missing. The `get_details=True` argument provides additional information like best-before dates and missing amounts. ```python # Get due/overdue/expired/missing products print("Due:") for p in grocy.stock.due_products(get_details=True): print(f" {p.name} - best before: {p.best_before_date}") print("\nOverdue:") for p in grocy.stock.overdue_products(get_details=True): print(f" {p.name}") print("\nExpired:") for p in grocy.stock.expired_products(get_details=True): print(f" {p.name}") print("\nMissing:") for p in grocy.stock.missing_products(get_details=True): print(f" {p.name} - missing: {p.amount_missing}") ``` -------------------------------- ### Initialize Grocy Client with Custom Port and SSL Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Initialize the Grocy client with custom port and SSL verification options. Set verify_ssl to True to enable SSL verification. ```python grocy = Grocy("https://example.com", "GROCY_API_KEY", port=9192, verify_ssl=True) ``` -------------------------------- ### Get fulfillment status for all recipes Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves the fulfillment status for all recipes in grocy, showing which recipes are fulfilled and the count of missing products for each. This provides a comprehensive overview for inventory management. ```python # Get all recipes' fulfillment status all_fulfillment = grocy.recipes.all_fulfillment() for f in all_fulfillment: print( f"Recipe {f.recipe_id}: fulfilled={f.need_fulfilled}, missing={f.missing_products_count}" ) ``` -------------------------------- ### User Management Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Operations for managing users, including retrieving the current user, listing all users, getting a specific user, creating, editing, deleting users, and managing user settings. ```APIDOC ## User Operations ### Description Provides methods to interact with user accounts within Grocy. ### Methods - `grocy.users.current()`: Retrieves information about the currently logged-in user. - `grocy.users.list()`: Returns a list of all users. - `grocy.users.get(user_id)`: Retrieves a specific user by their ID. - `grocy.users.create(data)`: Creates a new user with the provided data. - `grocy.users.edit(user_id, data)`: Edits an existing user identified by `user_id` with the provided `data`. - `grocy.users.delete(user_id)`: Deletes a user identified by `user_id`. - `grocy.users.settings()`: Retrieves all user settings. - `grocy.users.set_setting(key, value)`: Sets a specific user setting. - `grocy.users.get_setting(key)`: Retrieves a specific user setting. - `grocy.users.delete_setting(key)`: Deletes a specific user setting. ### Parameters - `user_id` (int): The ID of the user. - `data` (dict): A dictionary containing user attributes for creation or editing. - `key` (str): The key for a user setting. - `value` (str): The value for a user setting. ``` -------------------------------- ### Delete a Grocy Object Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Provides an example of how to delete an object from Grocy using its entity type and object ID. ```python # Delete an object # grocy.generic.delete(EntityType.LOCATIONS, object_id=1) ``` -------------------------------- ### Query, Add, Consume, and Open Stock Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/stock.md Demonstrates how to retrieve current stock levels for all products and perform basic stock operations like adding, consuming, and marking items as opened. Ensure product IDs and amounts are correctly specified. ```python # Get all products currently in stock for product in grocy.stock.current(): print(f"{product.name}: {product.available_amount}") # Add, consume, open grocy.stock.add(product_id=1, amount=5, price=2.99) grocy.stock.consume(product_id=1, amount=1) grocy.stock.open(product_id=1) ``` -------------------------------- ### File Operations (Upload, Download, Delete) Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/files.md Demonstrates how to upload, download, and delete files using the FileManager. Ensure the file is opened in binary read mode ('rb') for uploads and downloads. ```python # Upload a file with open("photo.jpg", "rb") as f: grocy.files.upload(group="productpictures", file_name="photo.jpg", data=f) # Download a file data = grocy.files.download(group="productpictures", file_name="photo.jpg") # Delete a file grocy.files.delete(group="productpictures", file_name="photo.jpg") ``` -------------------------------- ### Grocy Class Initialization Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/grocy.md The Grocy class is the primary entry point for the library. It requires the grocy instance URL and an API key for authentication. ```APIDOC ## Grocy Class ### Description The `Grocy` class serves as the main entry point for the library. It encapsulates the low-level API client and provides access to grocy data through rich data model objects. ### Usage To initialize the `Grocy` class, you need to provide the URL of your grocy instance and your API key. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Initialization ```python from grocy import Grocy grocy = Grocy("https://your-grocy-instance.com", "YOUR_API_KEY") ``` ### Response #### Success Response (Initialization) An instance of the `Grocy` class is returned upon successful initialization. #### Response Example ```python # No direct response example for initialization, but the grocy object is now available for use. ``` ``` -------------------------------- ### Connect to Local Docker Instance Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Connect to the locally running Dockerized Grocy instance using the provided URL, API key, and port. This snippet demonstrates iterating through current stock. ```python from grocy import Grocy grocy = Grocy("http://localhost", "test_local_devenv", port=9192) for product in grocy.stock.current(): print(f"{product.name}: {product.available_amount}") ``` -------------------------------- ### List Equipment with Details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/equipment.md Iterates through all equipment items, fetching their full details. Use this to access properties like name and description for each item. ```python for e in grocy.equipment.list(get_details=True): print(f"{e.name}: {e.description}") ``` -------------------------------- ### Calendar Access Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Provides methods to retrieve the Grocy calendar data in iCalendar format and to get a calendar sharing link. ```APIDOC ## Calendar Operations ### Description Provides methods to access calendar-related data. ### Methods - `grocy.calendar.ical()`: Returns the calendar data in iCalendar format. - `grocy.calendar.sharing_link()`: Returns a URL for sharing the calendar. ### Response - `grocy.calendar.ical()`: Returns a string containing the iCalendar data. - `grocy.calendar.sharing_link()`: Returns a string containing the sharing link URL. ``` -------------------------------- ### List all equipment Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves and displays all equipment items, including their names and descriptions. This provides an overview of available equipment. ```python # List all equipment equip = grocy.equipment.list(get_details=True) for e in equip: print(f"{e.id}: {e.name} - {e.description}") ``` -------------------------------- ### Manage Shopping List Items Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates how to retrieve, add, remove, and mark items in the shopping list. Requires grocy-py to be initialized. ```python # Get shopping list items items = grocy.shopping_list.items(get_details=True) for item in items: print(f"{item.product.name}: {item.amount} (done: {item.done})") # Add / remove products grocy.shopping_list.add_product(product_id=1, amount=3) grocy.shopping_list.remove_product(product_id=1, amount=1) # Mark an item as done / not done grocy.shopping_list.mark_item_done(shopping_list_item_id=1, done=True) grocy.shopping_list.mark_item_done(shopping_list_item_id=1, done=False) # Bulk operations grocy.shopping_list.add_missing_products() grocy.shopping_list.add_overdue_products() grocy.shopping_list.add_expired_products() # Clear the shopping list grocy.shopping_list.clear() ``` -------------------------------- ### Grocy File Operations (Upload, Download, Delete) Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Demonstrates how to upload, download, and delete files within Grocy. Supported file groups include 'productpictures', 'recipepictures', and 'equipmentmanuals'. ```python # Upload / download / delete files # File groups: "productpictures", "recipepictures", "equipmentmanuals", etc. # grocy.files.upload(group="productpictures", file_name="photo.jpg", data=open("photo.jpg", "rb")) # data = grocy.files.download(group="productpictures", file_name="photo.jpg") # grocy.files.delete(group="productpictures", file_name="photo.jpg") ``` -------------------------------- ### Access Grocy Calendar Data Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Provides methods to get the calendar data in iCalendar format and to retrieve a calendar sharing link. ```python # Get calendar in iCalendar format ical = grocy.calendar.ical() # Get a sharing link link = grocy.calendar.sharing_link() ``` -------------------------------- ### Shopping List Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/shopping_list.md Demonstrates how to retrieve shopping list items with details, add a specific product with a given amount, and add all missing products. ```python items = grocy.shopping_list.items(get_details=True) for item in items: print(f"{item.product.name}: {item.amount}") grocy.shopping_list.add_product(product_id=1, amount=3) grocy.shopping_list.add_missing_products() ``` -------------------------------- ### Manage Files in Grocy Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Demonstrates uploading, downloading, and deleting files within Grocy. Includes a convenience method for uploading product pictures. ```python # Upload a file with open("photo.jpg", "rb") as f: grocy.files.upload(group="productpictures", file_name="photo.jpg", data=f) # Download a file data = grocy.files.download(group="productpictures", file_name="photo.jpg") # Delete a file grocy.files.delete(group="productpictures", file_name="photo.jpg") # Convenience: upload a product picture grocy.stock.upload_product_picture(product_id=1, pic_path="/path/to/photo.jpg") ``` -------------------------------- ### grocy-py Architecture Overview Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/index.md Provides a high-level overview of the grocy-py library's architecture, outlining the key components and their roles in interacting with the Grocy API. ```Text grocy ├── Grocy # High-level client (you use this) ├── GrocyApiClient # Low-level HTTP API wrapper ├── Data Models # Rich domain objects (Product, Chore, Task, ...) ├── API Responses # Pydantic models for raw API responses ├── Enums # EntityType, TransactionType, etc. └── Errors # GrocyError exception ``` -------------------------------- ### List Grocy Objects with Query Filters Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Illustrates how to filter lists of objects based on specific criteria, such as name or ID. Grocy supports various query filter syntaxes. ```python # List with query filters # Grocy supports query filters like: "name=", "id<10", etc. # products = grocy.generic.list(EntityType.PRODUCTS, query_filters=["name=Cookies"]) # print(products) ``` -------------------------------- ### Get Last Database Change Time Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieve the timestamp of the last modification to the grocy database. This can be useful for tracking data changes or synchronization purposes. ```python # Get last database change time db_time = grocy.system.db_changed_time() print(f"DB last changed: {db_time}") ``` -------------------------------- ### grocy.system.info Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/system.md Retrieves general system information, including the Grocy version. ```APIDOC ## grocy.system.info ### Description Retrieves general system information. ### Method ```python info = grocy.system.info() ``` ### Parameters None ### Response Returns an object containing system information, including `grocy_version`. ### Response Example ```json { "grocy_version": "" } ``` ``` -------------------------------- ### Create a New Grocy Object Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Demonstrates how to create a new object within a specified entity type. Requires a dictionary containing the data for the new object. ```python # Create a new object # result = grocy.generic.create(EntityType.LOCATIONS, {"name": "Pantry", "description": "Kitchen pantry"}) # print(result) ``` -------------------------------- ### Copy a Recipe Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Creates a duplicate of an existing recipe. ```python # Copy a recipe grocy.recipes.copy(recipe_id=1) ``` -------------------------------- ### Fetch Stock Details with get_details Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Use `get_details=True` to fetch full object details, which requires additional API calls. Without it, only summary data is returned. ```python # Summary only (1 API call) stock = grocy.stock.current() # Full details (1 + N API calls) due = grocy.stock.due_products(get_details=True) for product in due: print(product.name) # available with details print(product.barcodes) # available with details ``` -------------------------------- ### Get Grocy Calendar Sharing Link Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves the iCal sharing link for the Grocy calendar. This link can be used to subscribe to your Grocy calendar in external applications. ```python # Get calendar sharing link link = grocy.calendar.sharing_link() print(f"Sharing link: {link}") ``` -------------------------------- ### Get a specific battery Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches details for a specific battery by its ID, including its charge cycles and charging interval. Use this to inspect individual battery performance. ```python # Get a specific battery battery = grocy.batteries.get(battery_id=1) if battery: print( f"{battery.name}: cycles={battery.charge_cycles_count}, interval={battery.charge_interval_days} days" ) ``` -------------------------------- ### Lint and Format Code Source: https://github.com/iamkarlson/grocy-py/blob/main/README.md Apply linting and formatting to the project code using ruff. ```bash # Lint and format uv run ruff check . uv run ruff format . ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Set the `debug` parameter to `True` when initializing the Grocy client to enable detailed logging of HTTP requests and responses. This is useful for troubleshooting. ```python grocy = Grocy("https://example.com", "API_KEY", debug=True) ``` -------------------------------- ### Get a Single Grocy Object by ID Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves a single object of a specified entity type using its unique ID. This is useful for fetching details of a particular item. ```python # Get a single object locations = grocy.generic.list(EntityType.LOCATIONS) if locations: loc = grocy.generic.get(EntityType.LOCATIONS, object_id=locations[0]["id"]) print(loc) ``` -------------------------------- ### User Settings Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/users.md Retrieves all user settings. ```APIDOC ## User Settings ### Description Retrieves all user settings. ### Method ```python grocy.users.settings() ``` ### Response Returns a dictionary or object containing user settings. ``` -------------------------------- ### Open Product Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Marks a specified amount of a product as opened. This can be useful for tracking partially used items. ```python # Open a product (mark as opened) grocy.stock.open(product_id=1, amount=1) ``` -------------------------------- ### Basic Grocy Connection Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Connect to your Grocy instance using the base URL and API key. Ensure your Grocy instance is running and API access is enabled. ```python from grocy import Grocy # Basic connection grocy = Grocy("https://your-grocy-instance.com", "YOUR_API_KEY") ``` -------------------------------- ### List All Users Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Retrieves a list of all users in the grocy system and prints their ID, username, and display name. Ensure you have the necessary permissions to list users. ```python # List all users users = grocy.users.list() for user in users: print(f"{user.id}: {user.username} ({user.display_name})") ``` -------------------------------- ### EquipmentManager.list Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/equipment.md Retrieves a list of equipment. Can optionally fetch full details for each item. ```APIDOC ## EquipmentManager.list ### Description Retrieves a list of equipment. Can optionally fetch full details for each item. ### Method `list` ### Parameters #### Query Parameters - **get_details** (bool) - Optional - If True, fetches full details for each equipment item. ### Request Example ```python for e in grocy.equipment.list(get_details=True): print(f"{e.name}: {e.description}") ``` ### Response #### Success Response (200) - **equipment_list** (list) - A list of equipment objects. - Each object may contain fields like `id`, `name`, `description`, etc., if `get_details` is True. ``` -------------------------------- ### Generic Entity Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/generic.md Perform CRUD operations on Grocy entities using the GenericEntityManager. This includes listing, getting, creating, updating, and deleting entities of a specified type. ```APIDOC ## Generic Entity Manager Operations ### Description Provides methods to perform Create, Read, Update, and Delete (CRUD) operations on any Grocy entity type. Use `EntityType` for type safety when specifying the entity type. ### Methods #### `list(entity_type: EntityType)` Lists all entities of the specified type. #### `get(entity_type: EntityType, object_id: int)` Retrieves a specific entity of the given type by its ID. #### `create(entity_type: EntityType, data: dict)` Creates a new entity of the specified type with the provided data. #### `update(entity_type: EntityType, object_id: int, data: dict)` Updates an existing entity of the specified type identified by its ID with the provided data. #### `delete(entity_type: EntityType, object_id: int)` Deletes an entity of the specified type identified by its ID. ### User Fields Management #### `get_userfields(entity_type: str, object_id: int)` Retrieves custom user fields for a specified entity type and object ID. #### `set_userfields(entity_type: str, object_id: int, key: str, value: str)` Sets a custom user field for a specified entity type and object ID. This method allows for setting or updating a specific key-value pair for user-defined fields. ``` -------------------------------- ### Upload Product Picture (Convenience Method) Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb A convenience method to upload a picture for a specific product. Requires the product ID and the local path to the picture file. ```python # Upload a product picture (convenience method) # grocy.stock.upload_product_picture(product_id=1, pic_path="/path/to/photo.jpg") ``` -------------------------------- ### Consume Product from Stock Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Record the consumption of a product from stock. Requires the product ID and the amount consumed. ```python # Consume a product grocy.stock.consume(product_id=1, amount=1) ``` -------------------------------- ### StockManager.add Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/stock.md Adds a specified amount of a product to the stock, optionally with a price. ```APIDOC ## StockManager.add ### Description Adds a specified amount of a product to the stock, optionally with a price. ### Method `grocy.stock.add(product_id, amount, price=None)` ### Parameters #### Path Parameters - **product_id** (int) - Required - The ID of the product to add. - **amount** (int) - Required - The quantity of the product to add. - **price** (float) - Optional - The price per unit of the product. ### Response #### Success Response None (operation is performed). ### Request Example ```python grocy.stock.add(product_id=1, amount=5, price=2.99) ``` ``` -------------------------------- ### Get Current Logged-in User Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Fetches the details of the currently authenticated user. This is useful for personalizing the user experience or performing user-specific actions. It returns None if no user is logged in. ```python # Get current logged-in user me = grocy.users.current() if me: print(f"Logged in as: {me.username} ({me.display_name})") ``` -------------------------------- ### User Manager Operations Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/users.md Demonstrates common operations with the User Manager, including fetching the current user, listing all users, and managing user settings. Ensure the grocy instance is accessible. ```python # Current user me = grocy.users.current() print(f"Logged in as: {me.username}") # All users for user in grocy.users.list(): print(f"{user.id}: {user.username}") # User settings settings = grocy.users.settings() grocy.users.set_setting("my_key", "my_value") ``` -------------------------------- ### Merge Stock Products Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Demonstrates how to merge two products in the stock. The first product ID is kept, and the second is removed. ```python # Merge two products (keeps first, removes second) # grocy.stock.merge(product_id_keep=1, product_id_remove=2) ``` -------------------------------- ### Add Product to Stock Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/getting-started.md Add a specified amount of a product to the stock. Requires the product ID, amount to add, and optionally the price. ```python # Add product to stock grocy.stock.add(product_id=1, amount=5, price=2.99) ``` -------------------------------- ### Charge a battery Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/example.ipynb Initiates the charging process for a specified battery. This action records a new charge cycle for the battery. ```python # Charge a battery grocy.batteries.charge(battery_id=1) ``` -------------------------------- ### Iterate and Print Meal Plan Items Source: https://github.com/iamkarlson/grocy-py/blob/main/docs/reference/managers/meal_plan.md Iterates through all meal plan items, fetching full details for each. Prints the day and the name of the associated recipe or the note if no recipe is linked. ```python for meal in grocy.meal_plan.items(get_details=True): name = meal.recipe.name if meal.recipe else meal.note print(f"{meal.day}: {name}") ```