Also note that when you get to doing polymorphic wrappers, you're going to want to be able to distinguish the polymorphic wrapper type from the "logical" wrapped type T. To do that, you'll need to either roll your own or be willing to use non-public boost.python api. (detail::unwrap_wrapper).
I think I am a little lost here or missing something. I am definitely going to be using this code in in the presence of polymorphism.
Can you explain this part further or do you have a code example where you have had to do this?
The basic problem is that if you use the def_visitor approach I posted, then for classes exposed as polymorphic on the python side, Class::wrapped_type will be the polymorphic wrapper type (a class derived from boost::python::wrapper<T>) rather than T itself. This is important because when you register your to-python converter, you want it to be for ptr<T> not ptr<wrapper<T> >, so you need to get the unwrapped T. Doing this means either using detail::unwrap_wrapper, or rolling your own version of the same. If you don't use the def_visitor, then you won't have this problem because you'll use the right T explicitly for each wrapped class. However, I would recommend considering the def_visitor approach if you have a large system because it gives you a centralized place to add stuff to whole categories of classes. Does this make more sense? Here's what my def visitor could potentially look like, if you were comfortable with using non-public api: struct ref_ptr_stuff : def_visitor<ref_ptr_stuff> { friend class def_visitor_access; template <class Class, class Wrapper, class T> void register_conversion(Class &c, Wrapper *, T *) { to_python_converter<ptr<T>, ptr_to_python<T> >(); } template <class Class> void visit(Class &c) const { typedef typename Class::wrapped_type T; register_conversion(c, (T *)0, detail::unwrap_wrapper((T *)0)); } }; Of course, in this example I don't need Wrapper in register_conversion, but I thought I'd leave it to be illustrative. Also, let me reemphasize that this is non-public api. If you're able to do partial specialization, I believe you can roll your own unwrap_wrapper that works in a nicer way. Alex