decimal.localcontext(ctx=None)
Return a context manager that will set the current context for the active thread to a copy of ctx on entry to the with-statement and restore the previous context when exiting the with-statement. If no context is specified, a copy of the current context is used.
For example, the following code sets the current decimal precision to 42 places, performs a calculation, and then automatically restores the previous context:
from decimal import localcontext
with local