How do I find the users of a datablock using the Python API? Given a datablock foo, how do I determine which other datablocks are referencing it? foo.users will tell me how many references there are, but do I have to loop through every other datablock in the file to find those references? If so, can anyone recommend a reasonably generic way of doing this given the different interfaces of various datablock types?

For my specific application I'm trying to find and delete (or modify) datablocks with names matching a pattern. I'm mostly interested in node groups and images, which seem to acquire hidden users more easily than other objects, but this type of functionality seems generally useful.
There is no way, internally Blender also doesn't store this data for easy access.

However some data types have convenience properties added to them to access some of the users.


Object.users_scene
Object.users_group
Object.children


Are handy in many cases, but specific to object types.