> ## 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.

# Library Snippets

> Share reusable Python modules across your team's Locust tests.

Library snippets are Python files that LoadForge distributes to all runners so you can `import` them from your Locust tests. Create a module like `custom_logger.py` and then import it with `import custom_logger` at the top of your locustfile.

## What libraries are for

* Reusable helpers (auth, signing, payload builders)
* Constants and configuration values
* Custom loggers and instrumentation
* Domain-specific client wrappers

<Info>Library files must end with `.py`. They are team-scoped and available to every worker at runtime.</Info>

## Using a library in a test

```python theme={null}
# In Library: custom_logger.py
def log_ok(client, name):
    client.environment.events.request.fire(
        request_type="CUSTOM",
        name=name,
        response_time=0,
        response_length=0,
        exception=None,
        context={},
    )
```

```python theme={null}
# In your locustfile
from locust import HttpUser, task, between
import custom_logger

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

    @task
    def index(self):
        r = self.client.get("/")
        if r.ok:
            custom_logger.log_ok(self.client, "index")
```

## Structure and imports

* One module per file, e.g., `utils.py` → `import utils`
* Subpackages are not supported; keep modules flat
* Avoid long import times; module code runs on import

## Best practices

* Keep helpers pure and side-effect free when possible
* Version modules via names (e.g., `auth_v2.py`) if making breaking changes
* Add docstrings and clear function names for readability

## Related

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