# Source: https://docs.runpod.io/serverless/quickstart.md

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runpod.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Write a handler function, build a worker image, create an endpoint, and send your first request.

<Tip>
  For an even faster start, clone or download the [worker-basic](https://github.com/runpod-workers/worker-basic) repository for a pre-configured template for building and deploying Serverless workers. After cloning the repository, skip to [step 6 of this tutorial](#step-6%3A-build-and-push-your-docker-image) to deploy and test the endpoint.
</Tip>

## What you'll learn

In this tutorial you'll learn how to:

* Set up your development environment.
* Create a handler function.
* Test your handler locally.
* Create a Dockerfile to package your handler function.
* Build and push your worker image to Docker Hub.
* Deploy your worker to a Serverless endpoint using the Runpod console.
* Send a test request to your endpoint.

## Requirements

* You've [created a Runpod account](/get-started/manage-accounts).
* You've installed [Python 3.x](https://www.python.org/downloads/) and [Docker](https://docs.docker.com/get-started/get-docker/) on your local machine and configured them for your command line.

## Step 1: Create a Python virtual environment

First, set up a virtual environment to manage your project dependencies.

<Steps>
  <Step title="Create a virtual environment">
    Run this command in your local terminal:

    ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
    # Create a Python virtual environment
    python3 -m venv venv
    ```
  </Step>

  <Step title="Activate the virtual environment">
    <Tabs>
      <Tab title="macOS/Linux">
        ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
        source venv/bin/activate
        ```
      </Tab>

      <Tab title="Windows">
        ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
        venv\Scripts\activate
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Install the Runpod SDK">
    ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
    pip install runpod
    ```
  </Step>
</Steps>

## Step 2: Create a handler function

Create a file named `handler.py` and add the following code:

```python handler.py theme={"theme":{"light":"github-light","dark":"github-dark"}}
import runpod
import time  

def handler(event):
#   This function processes incoming requests to your Serverless endpoint.
#
#    Args:
#        event (dict): Contains the input data and request metadata
#       
#    Returns:
#       Any: The result to be returned to the client
    
    # Extract input data
    print(f"Worker Start")
    input = event['input']
    
    prompt = input.get('prompt')  
    seconds = input.get('seconds', 0)  

    print(f"Received prompt: {prompt}")
    print(f"Sleeping for {seconds} seconds...")
    
    # You can replace this sleep call with your own Python code
    time.sleep(seconds)  
    
    return prompt 

# Start the Serverless function when the script is run
if __name__ == '__main__':
    runpod.serverless.start({'handler': handler })
```

This is a bare-bones handler that processes a JSON object and outputs a `prompt` string contained in the `input` object. You can replace the `time.sleep(seconds)` call with your own Python code for generating images, text, or running any machine learning workload.

## Step 3: Create a test input file

You'll need to create an input file to properly test your handler locally. Create a file named `test_input.json` and add the following code:

```json test_input.json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "input": {
        "prompt": "Hey there!"
    }
}
```

## Step 4: Test your handler function locally

Run your handler function to verify that it works correctly:

```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
python handler.py
```

You should see output similar to this:

```text  theme={"theme":{"light":"github-light","dark":"github-dark"}}
--- Starting Serverless Worker |  Version 1.7.9 ---
INFO   | Using test_input.json as job input.
DEBUG  | Retrieved local job: {'input': {'prompt': 'Hey there!'}, 'id': 'local_test'}
INFO   | local_test | Started.
Worker Start
Received prompt: Hey there!
Sleeping for 0 seconds...
DEBUG  | local_test | Handler output: Hey there!
DEBUG  | local_test | run_job return: {'output': 'Hey there!'}
INFO   | Job local_test completed successfully.
INFO   | Job result: {'output': 'Hey there!'}
INFO   | Local testing complete, exiting.
```

## Step 5: Create a Dockerfile

Create a file named `Dockerfile` with the following content:

```dockerfile Dockerfile theme={"theme":{"light":"github-light","dark":"github-dark"}}
FROM python:3.10-slim

WORKDIR /

# Install dependencies
RUN pip install --no-cache-dir runpod

# Copy your handler file
COPY handler.py /

# Start the container
CMD ["python3", "-u", "handler.py"]
```

## Step 6: Build and push your worker image

<Tip>
  Instead of building and pushing your image via Docker Hub, you can also [deploy your worker from a GitHub repository](/serverless/workers/github-integration).
</Tip>

Before you can deploy your worker on Runpod Serverless, you need to push it to Docker Hub:

<Steps>
  <Step title="Build your Docker image">
    Build your Docker image, specifying the platform for Runpod deployment, replacing `[YOUR_USERNAME]` with your Docker username:

    ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker build --platform linux/amd64 --tag [YOUR_USERNAME]/serverless-test .
    ```
  </Step>

  <Step title="Push the image to your container registry">
    ```sh  theme={"theme":{"light":"github-light","dark":"github-dark"}}
    docker push [YOUR_USERNAME]/serverless-test:latest
    ```
  </Step>
</Steps>

## Step 7: Deploy your worker using the Runpod console

To deploy your worker to a Serverless endpoint:

1. Go to the [Serverless section](https://www.console.runpod.io/serverless) of the Runpod console.
2. Click **New Endpoint**.
3. Click **Import from Docker Registry**
4. In the **Container Image** field, enter your Docker image URL: `docker.io/yourusername/serverless-test:latest`.
5. Click **Next** to proceed to endpoint configuration.
6. Configure your endpoint settings:
   * (Optional) Enter a custom name for your endpoint, or use the randomly generated name.
   * Make sure the **Endpoint Type** is set to **Queue**.
   * Under **GPU Configuration**, check the box for **16 GB** GPUs.
   * Leave the rest of the settings at their defaults.
7. Click **Deploy Endpoint**.

The system will redirect you to a dedicated detail page for your new endpoint.

## Step 8: Test your endpoint

To test your endpoint, click the **Requests** tab in the endpoint detail page:

<Frame>
  <img src="https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=d68657d269fbc6a2459a586c8fb64058" data-og-width="1403" width="1403" data-og-height="631" height="631" data-path="images/8f34ba77-serverless-get-started-endpoint-details.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=280&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=89e717cb22c1fd4d0f0dbb6763a72a66 280w, https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=560&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=beefd2f40feb862a0cd2611854021183 560w, https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=840&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=56a0651a2ba910720d401ba7e4a91953 840w, https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=1100&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=27f35512954ca7927195025770921b1e 1100w, https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=1650&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=367eb72b0969c42a2bde5776423c958b 1650w, https://mintcdn.com/runpod-b18f5ded/QcR4sHy3480YmZ2d/images/8f34ba77-serverless-get-started-endpoint-details.png?w=2500&fit=max&auto=format&n=QcR4sHy3480YmZ2d&q=85&s=ae1da0c76e3ab9c7796d08b6a0693ed6 2500w" />
</Frame>

On the left you should see the default test request:

```json  theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "input": {
        "prompt": "Hello World"
    }
}
```

Leave the default input as is and click **Run**. The system will take a few minutes to initialize your workers.

When the workers finish processing your request, you should see output on the right side of the page similar to this:

```json  theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "delayTime": 15088,
    "executionTime": 60,
    "id": "04f01223-4aa2-40df-bdab-37e5caa43cbe-u1",
    "output": "Hello World",
    "status": "COMPLETED",
    "workerId": "uhbbfre73gqjwh"
}
```

Congratulations! You've successfully deployed and tested your first Serverless endpoint.

## Next steps

Now that you've learned the basics, you're ready to:

* [Create more advanced handler functions.](/serverless/workers/handler-functions)
* [Update your Dockerfile with AI/ML models and other dependencies.](/serverless/workers/create-dockerfile)
* [Learn how to structure and send requests to your endpoint.](/serverless/endpoints/send-requests)
* [Manage your Serverless endpoints in the Runpod console.](/serverless/endpoints/overview)