# Range

Range type with inclusive and exclusive bound support.

A `Range` represents a SurrealDB range value with a begin and end bound. Each bound can be inclusive or exclusive. `Range` is a Python dataclass.

```python title="Import"
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded, BoundExcluded
```

---

## `Bound` classes {#bounds}

The `Bound` base class has two subclasses that define whether a boundary value is included or excluded.

### `BoundIncluded` {#boundincluded}

An inclusive bound. The boundary value is part of the range.

<table>
    <thead>
        <tr>
            <th>Property</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>value</code></td>
            <td><code><a href="/docs/reference/python/api/values/#value">Value</a></code></td>
            <td>The boundary value.</td>
        </tr>
    </tbody>
</table>

### `BoundExcluded` {#boundexcluded}

An exclusive bound. The boundary value is not part of the range.

<table>
    <thead>
        <tr>
            <th>Property</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>value</code></td>
            <td><code><a href="/docs/reference/python/api/values/#value">Value</a></code></td>
            <td>The boundary value.</td>
        </tr>
    </tbody>
</table>

---

## `Range` dataclass {#range-dataclass}

### Fields {#fields}

| Field | Type | Description |
|---|---|---|
| `begin` | `Bound` | The start bound of the range. |
| `end` | `Bound` | The end bound of the range. |

### Constructor {#constructor}

```python title="Syntax"
Range(begin, end)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>begin</code> _(required)_</td>
            <td><code>Bound</code></td>
            <td>The start bound (inclusive or exclusive).</td>
        </tr>
        <tr>
            <td><code>end</code> _(required)_</td>
            <td><code>Bound</code></td>
            <td>The end bound (inclusive or exclusive).</td>
        </tr>
    </tbody>
</table>

---

## Examples {#examples}

```python title="Inclusive range 1 to 10"
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded

r = Range(
    begin=BoundIncluded(1),
    end=BoundIncluded(10),
)
```

```python title="Half-open range 1 to 10"
from surrealdb.data.types.range import BoundIncluded, BoundExcluded

r = Range(
    begin=BoundIncluded(1),
    end=BoundExcluded(10),
)
```

```python title="Using with queries"
from surrealdb import Surreal, Range
from surrealdb.data.types.range import BoundIncluded

with Surreal("ws://localhost:8000") as db:
    db.use("my_ns", "my_db")
    db.signin({"username": "root", "password": "secret"})

    events = db.query(
        "SELECT * FROM events WHERE year IN $range",
        {"range": Range(BoundIncluded(2020), BoundIncluded(2025))},
    ).first()
```

---

## See also

- [Data types](/docs/reference/python/api/values.md) - All SDK data types
- [RecordID](/docs/reference/python/api/values/record-id.md) - Record identifier
