How to declare a module deprecated in python?
I want a warning to be printed whenever a particular module is imported or any of its functions are called.
You want to warn with a DeprecationWarning.
Exactly how you call it doesn't matter that much, but the stdlib has a standard pattern for deprecated modules, like this:
# doc string, top-level comments, imports, __all__ =
import warnings
warnings.warn("the spam module is deprecated", DeprecationWarning,
stacklevel=2)
# normal module code
See the 2.7 sets source for an example.