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

# Files in Tests

> Upload CSV/JSON/TXT to files/ and use them in Locust tests.

Files let you ship data alongside your tests. When you upload a file in LoadForge, it is automatically made available on all runners for your team under the `files/` directory, so your test code can open it directly.

## What files are for

* CSV datasets for data-driven scenarios
* JSON config or fixtures
* Text lists (e.g., usernames, URLs)

<Info>Files are team-scoped and synced to every worker. You do not need to upload them per region or run.</Info>

## Where files live

* Path on runners: `files/{your_file_name}`
* Supported extensions: `.csv`, `.json`, `.txt`

## Using files in Locust

### CSV example

```python theme={null}
import csv
import random
from locust import HttpUser, task, between

class DataDrivenUser(HttpUser):
    wait_time = between(1, 3)

    def on_start(self):
        self.rows = []
        with open('files/test_data.csv', 'r') as f:
            reader = csv.DictReader(f)
            self.rows = list(reader)

    @task
    def submit(self):
        payload = random.choice(self.rows)
        self.client.post('/api/submit', payload)
```

### JSON example

```python theme={null}
import json
from locust import HttpUser, task, between

class ConfigUser(HttpUser):
    wait_time = between(1, 5)

    def on_start(self):
        with open('files/config.json', 'r') as f:
            self.cfg = json.load(f)

    @task
    def call(self):
        for endpoint in self.cfg['endpoints']:
            self.client.get(endpoint['url'], name=endpoint['name'])
```

## Best practices

* Keep files reasonably small for fast sync
* Load once in `on_start` rather than per request
* Use structured formats (CSV/JSON) when possible
* Validate rows and handle missing fields

## Related

* See API: `POST /api/v2/files` to create files programmatically
* See API: `GET /api/v2/files` to list files
