# tff.framework.ContextStack

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

An interface to a context stack for the API to run against.

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `current` | Returns the current context (one at the top of the context stack). |

<br />

## Methods

### `install`

[View source](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    @contextlib.contextmanager
    @abc.abstractmethod
    install(
        ctx
    )

A context manager that temporarily installs a new context on the stack.

The installed context is placed at the top on the stack while in the context
manager's scope, and remove from the stack upon exiting the scope. This
method should only be used by the implementation code, and by the unit tests
for dependency injection.

<br />

<br />

<br />

| Args ||
|---|---|
| `ctx` | The context to temporarily install at the top of the context stack, an instance of `Context` defined in `context_base.py`. |

<br />

<br />

<br />

<br />

| Yields ||
|---|---|
| The installed context. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `TypeError` | If `ctx` is not a valid instance of [`tff.framework.AsyncContext`](https://www.tensorflow.org/federated/api_docs/python/tff/framework/AsyncContext) or [`tff.framework.SyncContext`](https://www.tensorflow.org/federated/api_docs/python/tff/framework/SyncContext). |

<br />