# `SnakeBridge.WithContext`
[🔗](https://github.com/nshkrdotcom/snakebridge/blob/v0.14.0/lib/snakebridge/with_context.ex#L1)

Provides Python context manager support via `with_python/2` macro.

Ensures `__exit__` is always called, even on exception.

## Example

    SnakeBridge.with_python(file_ref) do
      SnakeBridge.Dynamic.call(file_ref, :read, [])
    end

# `call_enter`
[🔗](https://github.com/nshkrdotcom/snakebridge/blob/v0.14.0/lib/snakebridge/with_context.ex#L63)

```elixir
@spec call_enter(
  SnakeBridge.Ref.t() | map(),
  keyword()
) :: {:ok, term()} | {:error, term()}
```

Calls __enter__ on a Python context manager.

# `call_exit`
[🔗](https://github.com/nshkrdotcom/snakebridge/blob/v0.14.0/lib/snakebridge/with_context.ex#L72)

```elixir
@spec call_exit(SnakeBridge.Ref.t() | map(), Exception.t() | nil, keyword()) ::
  {:ok, term()} | {:error, term()}
```

Calls __exit__ on a Python context manager.

# `with_python`
[🔗](https://github.com/nshkrdotcom/snakebridge/blob/v0.14.0/lib/snakebridge/with_context.ex#L22)
*macro* 

Executes a block with a Python context manager.

Calls `__enter__` before the block and guarantees `__exit__` after,
even if an exception occurs.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
