---
title: DeviceHub Drivers
slug: sdk/Usage-Guideline-Authentication/devicehub-drivers
docTags: 
createdAt: 2025-03-20T19:56:50.280Z
---

The drivers module provides access to DeviceHub driver definitions and a bundled template library for offline use.

## Imports

```python
from litmussdk.devicehub import drivers                       # live API
from litmussdk.devicehub.record import DriverTemplates        # bundled templates
```

***

## Driver API

### Listing Drivers

```python
from litmussdk.devicehub import drivers

all_drivers = drivers.list_all_drivers()              # list[Driver]
```

Pass `raw=True` to skip pydantic validation and return the API JSON unchanged. Useful when the driver schema drifts ahead of your installed SDK.

```python
all_raw = drivers.list_all_drivers(raw=True)          # list[dict[str, Any]]
```

Each `Driver` is a Pydantic model with fields including:

- `id: str`
- `name: str`
- `driver_gen: str`: `"Gen1"` or `"Gen2"`
- `group_id: str`
- `properties: list[Property]`: valid device-level configuration fields
- `registers: list[SupportedRegister]`: valid register (tag) types for this driver
- `meta: Meta`: browse support, discovery support, version, etc.

```python
# Find a driver by name
driver = next((d for d in drivers.list_all_drivers() if d.name == "Simulator (Gen1)"), None)
driver_id = driver.id

# Or, with raw dicts
driver = next((d for d in drivers.list_all_drivers(raw=True) if d["Name"] == "Simulator (Gen1)"), None)
driver_id = driver["ID"]

# Get supported registers for a driver
details = next((d for d in drivers.list_all_drivers() if d.name == "Simulator (Gen1)"), None)
registers = details.registers
```

***

## Driver Templates

The SDK ships with a bundled set of driver definitions compiled from the Litmus Edge API. These let you look up driver IDs and validate device configuration without making live API calls.

:::BlockQuote
Templates are regenerated via the `download_dh_record` CLI command or during CI builds. Run `list_dh_versions` to see available versions and `get_dh_cache_dir` to find where they are cached.
:::

### Getting a Driver by Name or ID

```python
from litmussdk.devicehub.record import DriverTemplates, get_driver_by_name, driver_library_by_id

# From the DriverTemplates class (known drivers)
simulator = DriverTemplates.simulator_gen1
driver_id = simulator.id

# By name (searches the full library)
driver = get_driver_by_name("Simulator (Gen1)")

# By ID
driver = driver_library_by_id["50E3EDA1-11F9-41D6-9232-778A28665580"]
```

### Inspecting Driver Properties

```python
registers = DriverTemplates.simulator_gen1.registers
properties = DriverTemplates.simulator_gen1.properties
```

### Validating Device Configuration (JSON Schema)

Both `DriverTemplate` and `RegisterType` objects can generate a [JSON Schema](https://json-schema.org/) for their configuration fields, useful for client-side validation before making API calls.

```python
import jsonschema
from litmussdk.devicehub.record import DriverTemplates

device_config = {
    "networkAddress": "192.168.1.10",
    "networkPort": 102,
    "slotNumber": 0,
}

# Validates successfully against the Siemens S7 schema
jsonschema.validate(device_config, DriverTemplates.siemens_s7.schema)

# Raises ValidationError, wrong driver
jsonschema.validate(device_config, DriverTemplates.simulator_gen1.schema)
```

***

## Template Data Classes

### `DriverTemplate`

Represents a driver type with the following fields:

- `name: str`
- `id: str`
- `driver_gen: str`
- `group_id: str`
- `properties: list[PropertyType]`
- `registers: list[RegisterType]`
- `description: str` *(optional)*

### `RegisterType`

Represents a valid tag/register type for a driver:

- `name: str`
- `readonly: bool`
- `properties: list[PropertyType]`
- `description: str` *(optional)*

### `PropertyType`

Describes a single configuration field:

- `name: str`
- `value_type: str`
- `required: bool`
- `description: str | None`
- `default_value: str | None`
- `number_min: int | None`, `number_max: int | None`

***

## License

Copyright (c) Litmus Automation Inc.
