# Getting Data from a LabRat

We have put data into our LabRat, how do we get it out?

```{admonition}  Requirements
 :class: Hint

1. A computer wwith a working install of LabRat working, [follow the quick start guide](/LabRat/rat_quick_start.md)
2. Some data logged into LabRat from a device
```

## Display data

To display the data for a given inator device you can use the built in dashboard route
[CONNECTIONS.FLASK.DASH] as defined in the toml

```toml
VERSION = 1.0

[CONFIG]
    "AUTOBROW" = false # whether to automatically open the browser or not
    "ALLOW_SETUP" = false 
    "COMMAND_QUEUE" = true # whether to allow a command COMMAND_QUEUE to run

[LOGGING]
    [LOGGING.SQLITE]
        [LOGGING.SQLITE.MYDB]
            "FILE" = "path to the database as set up in quick start"
            "CREATE" = false

[CONNECTIONS]
    [CONNECTIONS.FLASK]
        "KEY" = "TO GENERATE SEE LABRAT README"
        "HOST" = "127.0.0.1"
        "PORT" = 8090

        "LOCAL_ON" = true
   
        [CONNECTIONS.FLASK.DASH]
            "ROUTE" = "/dash"

```

Once the LabRat is running then going to the host address and then the dashboard endpoint will show the dashboard.
In this example it would be found at

```bash
http://127.0.0.1:8090/dash
```

or

```bash
http://localhost:8090/dash
```

## Getting data to analyse

The dash route is good for displaying data, but sometimes you want to do more (or you prefer other plotting styles).
In that case you can use the *get* API route. This will return data from the chosen logging connection.

```toml
VERSION = 1.0

[CONFIG]
    "AUTOBROW" = false # whether to automatically open the browser or not
    "ALLOW_SETUP" = false 
    "COMMAND_QUEUE" = true # whether to allow a command COMMAND_QUEUE to run

[LOGGING]
    [LOGGING.SQLITE]
        [LOGGING.SQLITE.MYDB]
            "FILE" = "path to the database as set up in quick start"
            "CREATE" = false

[CONNECTIONS]
    [CONNECTIONS.FLASK]
        "KEY" = "TO GENERATE SEE LABRAT README"
        "HOST" = "127.0.0.1"
        "PORT" = 8090

        "LOCAL_ON" = true
        [CONNECTIONS.FLASK.API.GETDATA_API]
            "ROUTE" = "/api/getdata"
```

The following commmands will get the data from the connection for a given device
If the settings dictionary is left empty you will get *all* the data for a device (this can be a lot)
Note, even though the name of the route is get, it is actually a *POST* request

```bash
curl --location -X POST '<http://127.0.0.1:5000/api/getdata>' \
--header 'X-API-KEY: <REPLACE WITH YOUR FLASK KEY>' \
--header 'Content-Type: application/json' \
--data '{
  "name": "<REPLACE WITH CONNECTION NAME HERE>",
  "device_name": "<REPLACE WITH DEVICE NAME HERE>",
  "settings": {
    "start": "2026-05-01",
    "end": "2025-07-03 12:00:00"
  }
}'
```

```python
import requests

url = "http://127.0.0.1:5000/api/getdata"

headers = {
    "X-API-KEY": "<REPLACE WITH YOUR FLASK KEY>",
    "Content-Type": "application/json"
}

payload = {
    "name": "<REPLACE WITH CONNECTION NAME HERE>",
    "device_name": "<REPLACE WITH DEVICE NAME HERE>",
    "settings": {
        "start": "2026-05-01",
        "end": "2025-07-03 12:00:00"
    }
}

response = requests.post(url, json=payload, headers=headers)

print(response.status_code)
print(response.text)
```

The data is returned to the calling programme to be analysed as the user requires
