# Variable

## *class* <mark style="color:purple;">Variable</mark>

Variables represent the "columns" in tables (and uploads), and have certain metadata as well as detailed univariate summary statistics associated with them. Use this class to interface with variables and their metadata.

## Constructors

<table data-header-hidden><thead><tr><th width="342">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/uiC2PiNuiGTLEId4zOm0"><strong><code>query.list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) query's results.</td></tr><tr><td><a href="/pages/GNqdlKlXJ3D9gGr7pjOC"><strong><code>table.list_variables</code></strong></a>([max_results])</td><td>List all variables in a table.</td></tr><tr><td><a href="/pages/qbMXybSSBakBjZslZFN7"><strong><code>upload.list_variables</code></strong></a>([max_results])</td><td>List all variables in a (completed) upload.</td></tr><tr><td><a href="/pages/rgs1y0qJB47y2HslHTl0"><strong><code>query.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a query's results based on its (case-insensitive) name.</td></tr><tr><td><a href="/pages/I2341ba06MpBq2JWGyXc"><strong><code>table.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within a table based on its (case-insensitive) name.</td></tr><tr><td><a href="/pages/m6NIyMlGmGgsFfSkQZLf"><strong><code>upload.variable</code></strong></a>(variable_name)</td><td>Construct a reference to a variable within an upload based on its (case-insensitive) name.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

<pre class="language-python"><code class="lang-python"><strong>table = redivis.organization("Demo").dataset("iris_species").table("iris")
</strong>
variable = table.variable("sepalLengthCm")

variable.exists() # -> True
variable.get(wait_for_statistics=True) 

print(variable.properties)

{
"kind": "variable",
... (see variable resource definition)
}

print(variable.get_statistics())
{
  "kind": "variableStatistics"
  "status": "completed",
  "count": 150,
  "numDistinct": 35,
  "min": 4.3,
  "max": 7.9,
  "mean": 5.8433333333333355,
  "approxMedian": 0.8280661279778625,
  ...
}
</code></pre>

{% endtab %}
{% endtabs %}

## Attributes

| **`properties`** | A dict containing the [API resource representation of the variable](/api/resource-definitions/variable.md#base-definition). This will only be populated after certain methods are called, particularly the `get` method, and will otherwise be `None`. |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`table`**      | A reference to the [Table](/api/client-libraries/redivis-python/reference/table.md) instance that constructed this variable. Will be `None` if the variable belongs to an upload.                                                                      |
| **`upload`**     | A reference to the [Upload](/api/client-libraries/redivis-python/reference/upload.md) instance that constructed this variable. Will be `None` if the variable belongs to a table.                                                                      |

## Methods

<table data-header-hidden><thead><tr><th width="421">Name</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/O17sEEVzRGVWULt8zwWF"><strong><code>variable.get</code></strong></a>()</td><td>Gets the variable, after which the <code>properties</code> attribute will be populated according to the <a href="/pages/-LzteRAHYbTHSJ3jHiVl#get-definition">variable.get resource definition.</a></td></tr><tr><td><a href="/pages/Q6to4oS329UuVldA50bw"><strong><code>variable.get_statistics</code></strong></a>()</td><td>Gets the variable statistics, returning a dict corresponding the <a href="/pages/E9ZnqaNiEXqK6Stfebtv">variableStatistics resource definition.</a></td></tr><tr><td><a href="/pages/FhcFUHRm6yzhgsJnAm59"><strong><code>variable.exists</code></strong></a>()</td><td>List all visible datasets owned by the user.</td></tr><tr><td><a href="/pages/SaWOgHV2RkoYwSjBh7Ie"><strong><code>variable.update</code></strong></a>([*, label, description, ...])</td><td>Update a variable's metadata.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.redivis.com/api/client-libraries/redivis-python/reference/variable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
