How to setup custom data-structures in blender python? I am currently working on an add-on that is supposed to organise bones into clusters and to do fancy things with those clusters. You can look up the details here if you want. 

There is just one problem about my code. I have to come up with a data structure to save said "clusters". My first instinct would be to just write an empty class and fill it with memebers. But in Blender that seems to produce a ton of problems: 

import bpy
import os

#cleaning up the console
os.system("cls")

#this class is used to store stuff (oversimplified)
class Foo():
    #just setting up one element
    bar = None

#make instance of Foo()
foo = Foo()
foo.bar = "bar"

class dumbOperator(bpy.types.Operator):
    bl_idname = "test.dumb_operator"
    bl_label = "Dumb Operator"

    importedFoo = None

    def execute(self, context):
        if self.importedFoo.bar is not None:
            print(self.importedFoo.bar + " is here!")

class dumbPanel(bpy.types.Panel):
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Dumb"
    bl_label = "Dumb"

    def draw(self, context):
        lay = self.layout
        button =  lay.operator(dumbOperator.bl_idname)
        #this won't work
        button.importedFoo = foo

#registering stuff
def register():
    bpy.utils.register_class(dumbOperator)
    bpy.utils.register_class(dumbPanel)

def unregister():
    bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
    try:
        unregister()
    except Exception as e:
        print(e)
        pass
    register()


And even if I would somehow circumvent the problem shown in this example, there is just way more lurking around every corner (e.g. you can't make a CollectionProperty out of instances of custom classes, so layout.template_lists() are unavailable as well).

So why am I even using a custom class at the first place instead of a PropertyCollection? because I have no idea how to make a PropertyCollection out of this: 

class BoneCluster():
    """Simple class that is used to store groups of bones and some details about them
    Bones can be assigned to more than one instance of BoneCluster"""
    def __init__(self, name, parentCluster, prefix, bones, constraints):
        #The instances name. Will be set and read by the user
        self.name = name
        #If this instance of BoneCluster is a copy (thus a child) of another instance, a reference to it's "parent" will be stored
        self.parentCluster = parentCluster
        #If this instance of BoneCluster is a copy (thus a child) of another instance, all of the bones names inside it will begin with this prefix
        self.prefix = prefix
        #List of all bones, that are assigned to this instance
        self.bones = bones
        #List of all bone-constraints that link the bones inside this instance of BoneCluster to the corrsponding bones of it's respective parent
        self.constraints = constraints




Has anyone a solution to this dilemma?
Make your custom class a subclass of bpy.types.PropertyGroup, then you use that as the type for a bpy.props.CollectionProperty. See the collection example here.

I expect your collection should be part of the armature data, if you wanted a more global collection add it to bpy.types.Scene.

class BoneCluster(bpy.types.PropertyGroup):
    name = bpy.props.StringProperty()
    # ...

def register():
    bpy.types.Armature.clusters = bpy.props.CollectionProperty(type=BoneCluster)

def unregister():
    del bpy.types.Armature.clusters