• Start

Languages

/

Python

/

API Reference

/

Values

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.

Import
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded, BoundExcluded

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

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

Property

Type

Description

value

Value

The boundary value.

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

Property

Type

Description

value

Value

The boundary value.

FieldTypeDescription
beginBoundThe start bound of the range.
endBoundThe end bound of the range.
Syntax
Range(begin, end)

Parameter

Type

Description

beginBound

The start bound (inclusive or exclusive).

endBound

The end bound (inclusive or exclusive).

Inclusive range 1 to 10
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded

r = Range(
    begin=BoundIncluded(1),
    end=BoundIncluded(10),
)
Half-open range 1 to 10
from surrealdb.data.types.range import BoundIncluded, BoundExcluded

r = Range(
    begin=BoundIncluded(1),
    end=BoundExcluded(10),
)
Using with queries
from surrealdb import Surreal, Range
from surrealdb.data.types.range import BoundIncluded

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

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

Was this page helpful?