Range

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

Bound Classes

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

BoundIncluded

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

PropertyTypeDescription
valueValueThe boundary value.

BoundExcluded

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

PropertyTypeDescription
valueValueThe boundary value.

Range Dataclass

Fields

FieldTypeDescription
beginBoundThe start bound of the range.
endBoundThe end bound of the range.

Constructor

Syntax

Range(begin, end)
ParameterTypeDescription
begin BoundThe start bound (inclusive or exclusive).
end BoundThe end bound (inclusive or exclusive).

Examples

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))},
)

See Also