As I mentioned in my comment on @Martjin Pieters' answer, the id() builtin may be good enough for your needs. id(obj)
returns an id for any object in the system that is unique at the time of access (essentially, and in some interpreters literally, the memory address of the object). Unless your objects are being destroyed frequently but your id references need to stay valid even after destruction, id()
should work for your unique id needs.
From docs:
[The value returned by id()] is an integer (or long integer) which is guaranteed to be unique
and constant for this object during its lifetime. Two objects with
non-overlapping lifetimes may have the same id() value.