> For the complete documentation index, see [llms.txt](https://docs.cloud.hoverfly.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloud.hoverfly.io/create-simulations/using-data-sources-in-simulations.md).

# Using data sources in simulations

### Attaching a data source to a simulation

You can upload a csv file when editing your simulation from the Simulation tab.

You can both query data from a CSV data source as well as manipulate data within a data source by adding to it and deleting from it. Hoverfly supports a number of templating methods for simple read, update and delete functions. In addition Hoverfly supports a templating function that allows simple SQL like commands for SELECT, UPDATE and DELETE.

Note that you cannot edit the data sources on a simulation already running on a service. You need to add and remove data sources from the master copy of the simulation, and then start a service running a copy of that simulation.

<div data-full-width="false"><figure><img src="/files/4Ds8Oab95QALmZbsACMM" alt=""><figcaption><p>Add CSV data sources</p></figcaption></figure></div>

### Looking up a data value from within the response template

To use the data in the csv file, you need to use the {{ csv }} templating function.

```handlebars
{{csv '<data-source-name>' '<key-column>' '<key-value>' '<return-column>'}}
```

So for example given a data source named "products" with the following csv structure:

<figure><img src="/files/KGc0RcY55PIvrEaZZHxJ" alt=""><figcaption></figcaption></figure>

You can use the following syntax to render the word "shirt" in a response template (note the use of single quotes):

```handlebars
{{csv 'products' 'productId' '101' 'productName'}}
```

Or if for example the productId was provided at position 1 on the path:

```handlebars
{{csv 'products' 'productId' (Request.Path.[1]) 'productName'}}
```

Or if you needed to loop over some JSON array of productIds from the request body and render back data doing lookups for each productId:

```handlebars
{{#each (Request.Body 'jsonpath' '$.products')}}  
ProductId {{this}} is {{csv 'products' 'productId' this 'productName'}}
{{/each}}
```

There are a number of functions to allow querying, updating, deleting and inserting data into the csv data sources. You can read more about them below:

[<mark style="color:yellow;">Querying csv data sources</mark>](/create-simulations/using-data-sources-in-simulations/querying-data-sources.md)

[<mark style="color:yellow;">Updating csv data sources</mark>](/create-simulations/using-data-sources-in-simulations/updating-data-in-data-sources.md)

[<mark style="color:yellow;">Deleting data from csv data sources</mark>](/create-simulations/using-data-sources-in-simulations/deleting-data-from-data-sources.md)

[<mark style="color:yellow;">Inserting data into csv data sources</mark>](/create-simulations/using-data-sources-in-simulations/inserting-data-into-a-data-source.md)

[<mark style="color:yellow;">Guidance on using the SQL like syntax</mark>](/create-simulations/using-data-sources-in-simulations/guidance-on-using-the-sql-like-syntax.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cloud.hoverfly.io/create-simulations/using-data-sources-in-simulations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
