Python: How do I disallow imports of a class from a module?

import, python, python-import, python-module

Solution

The convention is to use a _ as a prefix:

class PublicClass(object):
    pass

class _PrivateClass(object):
    pass

The following:

from module import *

Will not import the _PrivateClass.

But this will not prevent them from importing it. They could still import it explicitly.

from module import _PrivateClass

Problem

I tried: ``` __all__ = ['SpamPublicClass'] ``` But, of course that's just for: ``` from spammodule import * ``` Is there a way to block importing of a class. I'm worried about confusion on the API level of my code that somebody will write: ``` from spammodule import SimilarSpamClass ``` and it'll cause debugging mayhem.

Original source