---
title: "Context"
description: "Share data between Workflow steps"
---

## Step Variables
Every step in a workflow has access to two built-in variables:

- **`.input`**: Contains a dictionary of all the parameters passed to the step. They are accessed through their name.
- **`.output`**: Contains the value(s) returned by the step. Can be a single value, dictionary, array, or custom class.

You can also create your own custom variables to share between steps:

```python
import asyncio
import datetime
from timbal import Workflow
from timbal.state import get_run_context

async def process_user_data(user_id: str):
    get_run_context().current_trace().user_status = "active"   # New variable
    return f"Processed user: {user_id}"

async def send_notification(message: str, user: str):
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    return [message, user, timestamp]


workflow = (Workflow(name='user_workflow')
    .step(process_user_data, user_id="user_123")
    .step(send_notification, message="Welcome!", user="user_123")
)
```

After the workflow runs, each step has the following variables in their context:

#### `process_user_data`:
```python
.input["user_id"]    = 'user_123'
.output              = 'Processed user: user_123'
.user_status         = 'active'
```

#### `send_notification`:
```python
.input["message"]    = 'Welcome!'
.input["user"]       = 'user_123'
.output[0]           = 'Welcome!'
.output[1]           = 'user_123'
.output[2]           = '2025-01-15 14:30:25'
```


### Variable Access
We have previously seen how to access the [Run Context](../core-concepts/context/#accessing-the-runcontext) to store additional data of the run.
Additionally, we can access the data from the parent and neighbour steps within the workflow.

- `current_trace()` - Access the current step's data
- `parent_trace()` - Access the parent workflow's data
- `step_trace("step_name")` - Access any specific neighbour step's data

```python
async def check_status():
    status = get_run_context().step_trace("process_user_data").user_status
    print(f"Your current status is: {status}")

workflow = (Workflow(name='user_workflow')
    .step(process_user_data, user_id="user_123")
    .step(send_notification, message="Welcome!", user="user_123")
    .step(check_status)
)
```
