How to declare a module deprecated in python
Question: 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.


Answer: You want to
[`warn`](https://docs.python.org/2/library/warnings.html#warnings.warn) with a
[`DeprecationWarning`](https://docs.python.org/2/library/exceptions.html#exceptions.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](https://hg.python.org/cpython/file/2.7/Lib/sets.py#l57) for an
example.

