It is often valuable to maintain a distinction between various phases of an application's lifecycle. The mode module calls these phases modes, and identifies four of them, given here in conceptual life-cycle order:
| Mode | Description |
|---|---|
debugging |
The application is being actively debugged; exceptions may trigger an interactive debugger. |
development |
The application is being actively developed; however, exceptions should not trigger interactive debugging. |
staging |
The application is deployed in a mock-production environment. |
production |
The application is in live use by its end users. |
The expectation is that various aspects of the application--logging, exception
handling, data sourcing--will adapt to the current mode. The mode is set in the
PYTHONMODE environment variable. This module provides API for
interacting with this variable. If PYTHONMODE is unset, it will be set
to development when this module is imported.
The module defines the following functions:
| ) |
debugging, development, staging, or production.
| mode) |
| ) |
os.environ mapping.
The module also defines a number of boolean attributes reflecting the current
mode setting, including abbreviations and combinations. Uppercase versions of
each of the following are also defined (e.g., DEBUGGING).
debugging.
development.
staging.
production.
debugging or development.
staging or production.
Example usage:
>>> import mode
>>> mode.set('development') # can set the mode at runtime
>>> mode.get() # and access the current mode
'development'
>>> mode.development # module defines boolean constants
True
>>> mode.PRODUCTION # uppercase versions are also defined
False
>>> mode.dev # as are abbreviations
True
>>> mode.DEBDEV, mode.stprod # and combinations
(True, False)
Aspen is copyright © 2006-2007 by Chad Whitacre and contributors, and is offered under the MIT license.