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

# Using the SDK with IaC

> Combine the Validio SDK client with Validio Code (IaC) to reuse the configuration of an existing validator.

## Overview

You can use the client to call the API as part of a [Validio Code (IaC)](https://docs.validio.io/developer/validio-code.md) setup. This is useful, for example, to copy a standard set of validators from another namespace, or to use values from a predetermined resource.

This recipe reads the dynamic threshold of an existing validator and applies the same threshold to a validator declared in code.

## Steps

**1. Get the sensitivity and decision bounds**

Write a function that accepts a validator name and the namespace it's in, and returns its threshold configuration. The validator could be a template validator, or one that is known to do the same thing as the validator you're declaring.

**2. Call the function**

Get the threshold configuration by calling the function. The client requires an asynchronous runtime, so use `asyncio.run` to run the request.

**3. Declare the validator**

Declare a validator in the global context as usual, and use the values from the other validator as input to its threshold. The window and segmentation are resources declared elsewhere in your Validio Code program.

## Full code sample

```python title="Python" theme={null}
import asyncio

from validio_sdk.client import Client
from validio_sdk.resource import validators
from validio_sdk.resource.thresholds import DecisionBoundsType, DynamicThreshold
from validio_sdk.resource.validators import VolumeMetric


async def sensitivity_and_decision_bounds(
    validator_name: str, namespace_id: str
) -> tuple[float, DecisionBoundsType]:
    client = Client()
    query = """
    query ValidatorByResourceName(
      $namespaceId: NamespaceId!,
      $resourceName: String!
    ) {
      validatorByResourceName(
        namespaceId: $namespaceId,
        resourceName: $resourceName
      ) {
        id
        ... on NumericValidator {
          config {
            threshold {
              ... on DynamicThreshold {
                decisionBoundsType
                sensitivity
              }
            }
          }
        }
      }
    }
    """

    result = await client.execute(
        query,
        variable_values={
            "namespaceId": namespace_id,
            "resourceName": validator_name,
        },
    )
    threshold = result["validatorByResourceName"]["config"]["threshold"]

    return threshold["sensitivity"], DecisionBoundsType(threshold["decisionBoundsType"])


sensitivity, decision_bounds_type = asyncio.run(
    sensitivity_and_decision_bounds("some_validator_name", "some_namespace")
)

# daily_window and unsegmented are a window and a segmentation declared
# elsewhere in your Validio Code program.
validators.VolumeValidator(
    name="unique_row_count",
    window=daily_window,
    segmentation=unsegmented,
    metric=VolumeMetric.UNIQUE_COUNT,
    threshold=DynamicThreshold(
        sensitivity=sensitivity,
        decision_bounds_type=decision_bounds_type,
    ),
)
```
