> ## Documentation Index
> Fetch the complete documentation index at: https://runpod-b18f5ded-promptless-websocket-streaming-tutorial.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Running code locally

Before deploying your serverless functions to the cloud, it's crucial to test them locally. In the previous lesson, [Hello World with Runpod](/tutorials/sdks/python/get-started/hello-world), you created a Python file called `hello_world.py`.

In this guide, you'll learn how to run your Runpod serverless applications on your local machine using the Runpod Python SDK.

## Understanding Runpod's Local Testing Environment

When you run your code locally using the Runpod Python SDK, here's what happens behind the scenes:

* FastAPI Server: The SDK spins up a FastAPI server on your local machine. This server simulates the Runpod serverless environment.
* Request Handling: The FastAPI server receives and processes requests just like the cloud version would, allowing you to test your function's input handling and output generation.
* Environment Simulation: The local setup mimics key aspects of the Runpod serverless environment, helping ensure your code will behave similarly when deployed.

## Running Your Code Locally

Let's walk through how to run your serverless functions locally using the Runpod Python SDK.

**Options for Passing Information to Your API**

The Runpod Python SDK offers two main methods for sending data to your local FastAPI server:

1. Using a JSON file
2. Using inline JSON via command line

Both methods allow you to simulate how your function would receive data in the actual cloud environment.

### Using a JSON File

1. Create a JSON file:

   Create a file called `test_input.json` with your test data:

   ```json test_input.json theme={null}
   {
     "input": {
       "name": "World"
     }
   }
   ```

2. Run the serverless function:

   Execute your `hello_world.py` script with the `--rp_server_api` flag:

   ```bash theme={null}
   python hello_world.py --rp_server_api
   ```

   The SDK will automatically look for and use the `test_input.json` file in the current directory.

### Using Inline JSON

You can also pass your test data directly via the command line:

```bash theme={null}
python hello_world.py --test_input '{"input": {"name": "World"}}'
```

This method is useful for quick tests or when you want to vary the input without editing a file.

### Understanding the output

When you run your function locally, you'll see output similar to this:

```bash theme={null}
--- Starting Serverless Worker |  Version 1.6.2 ---
INFO   | Using test_input.json as job input.
DEBUG  | Retrieved local job: {'input': {'name': 'World'}, 'id': 'local_test'}
INFO   | local_test | Started.
DEBUG  | local_test | Handler output: Hello World!
DEBUG  | local_test | run_job return: {'output': 'Hello World!'}
INFO   | Job local_test completed successfully.
INFO   | Job result: {'output': 'Hello World!'}
INFO   | Local testing complete, exiting.
```

This output provides valuable information:

* Confirmation that the Serverless Worker started successfully
* Details about the input data being used
* Step-by-step execution of your function
* The final output and job status

By analyzing this output, you can verify that your function is behaving as expected and debug any issues that arise.

### Key Takeaways

* Local testing with the Runpod Python SDK allows you to simulate the cloud environment on your machine.
* The SDK creates a FastAPI server to mock the serverless function execution.
* You can provide input data via a JSON file or inline JSON in the command line.
* Local testing accelerates development, reduces costs, and helps catch issues early.

Next, we'll explore the structure of Runpod handlers in more depth, enabling you to create more sophisticated serverless functions.
