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.
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.
Property | Type | Description |
|---|---|---|
value | Value | The boundary value. |
BoundExcluded
An exclusive bound. The boundary value is not part of the range.
Property | Type | Description |
|---|---|---|
value | Value | The boundary value. |
Range dataclass
Fields
| Field | Type | Description |
|---|---|---|
begin | Bound | The start bound of the range. |
end | Bound | The end bound of the range. |
Constructor
Range(begin, end)Parameter | Type | Description |
|---|---|---|
begin | Bound | The start bound (inclusive or exclusive). |
end | Bound | The end bound (inclusive or exclusive). |
Examples
from surrealdb import Range
from surrealdb.data.types.range import BoundIncluded
r = Range(
begin=BoundIncluded(1),
end=BoundIncluded(10),
)from surrealdb.data.types.range import BoundIncluded, BoundExcluded
r = Range(
begin=BoundIncluded(1),
end=BoundExcluded(10),
)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
Data types — All SDK data types
RecordID — Record identifier