Skip to content

Generic Entity Manager

CRUD operations for any Grocy entity type. Use EntityType for type safety.

Access via grocy.generic.

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)

# 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")

Class Reference

GenericEntityManager(api_client)

Perform CRUD operations on any Grocy entity type.

Access via grocy.generic.

list(entity_type, query_filters=None)

List all objects of a given entity type.

Parameters:

Name Type Description Default
entity_type EntityType

The Grocy entity type.

required
query_filters list[str] | None

Optional Grocy API query filters.

None

get(entity_type, object_id)

Get a single object by entity type and ID.

Parameters:

Name Type Description Default
entity_type EntityType

The Grocy entity type.

required
object_id int

The object ID.

required

create(entity_type, data)

Create a new object of a given entity type.

Parameters:

Name Type Description Default
entity_type EntityType

The Grocy entity type.

required
data

Object fields.

required

update(entity_type, object_id, data)

Update an existing object.

Parameters:

Name Type Description Default
entity_type EntityType

The Grocy entity type.

required
object_id int

The object ID.

required
data

Fields to update.

required

delete(entity_type, object_id)

Delete an object by entity type and ID.

get_userfields(entity, object_id)

Get custom userfields for an entity object.

Parameters:

Name Type Description Default
entity str

The entity type name string.

required
object_id int

The object ID.

required

set_userfields(entity, object_id, key, value)

Set a custom userfield value for an entity object.

Parameters:

Name Type Description Default
entity str

The entity type name string.

required
object_id int

The object ID.

required
key str

The userfield key.

required
value

The userfield value.

required