The Python SDK has classes for the SurrealDB values that Python has no type for, such as record IDs, durations and geometry. This section has a page for each class. This page lists those pages, maps each Python type to its SurrealDB type, and shows the Value union that the SDK uses for any value. For a guide to how values convert, with examples, see Value types.
Value classes
RecordID:
RecordIDnames one record by its table and ID, andStringRecordIdnames one as SurrealQL text.Table:
Tablenames a table, as a CRUD target or a query variable.Null:
Nullis the SurrealDBNULL, which is a different value fromNone.Datetime: Every datetime reads back as a
PreciseDatetime, andDatetimesends ISO 8601 text.Duration:
Durationholds a length of time in nanoseconds.SurrealSet: Every set reads back as a
SurrealSet, which the SDK writes back as a set.Range:
RangewithBoundIncludedandBoundExcludedholds a span of values or of record IDs.Geometry:
GeometryPointand six other classes hold geospatial data.File:
Filerefers to a file in a bucket, andFileMetadatadescribes a stored file.Sized numbers and BigDecimal:
I8toU64,F16,F32andBigDecimalhold the SurrealDB 4.0 number types.Dates, times and intervals:
PlainDate,PlainTime,TimestampandIntervalhold the SurrealDB 4.0 calendar types.Regex:
Regexholds a pattern for the SurrealDB 4.0regextype.
Type mapping
| Python | SurrealDB | Page |
|---|---|---|
None | NONE | Null |
Null | NULL | Null |
bool, int, float, str, bytes, uuid.UUID | bool, int, float, string, bytes, uuid | |
decimal.Decimal | decimal | Sized numbers and BigDecimal |
dict, list | object, array | |
set, frozenset, SurrealSet | set | SurrealSet |
datetime.datetime, PreciseDatetime, Datetime | datetime | Datetime |
Duration | duration | Duration |
RecordID, StringRecordId | record | RecordID |
Table | table | Table |
Range | range | Range |
GeometryPoint and the other geometry classes | geometry | Geometry |
File | file | File |
I8, U8, I16, U16, I32, U32, U64, F16, F32 | i8 to u64, f16, f32 (SurrealDB 4.0) | Sized numbers and BigDecimal |
BigDecimal | bigdecimal (SurrealDB 4.0) | Sized numbers and BigDecimal |
PlainDate, datetime.date | date (SurrealDB 4.0) | Dates, times and intervals |
PlainTime, naive datetime.time | time (SurrealDB 4.0) | Dates, times and intervals |
Timestamp | timestamp (SurrealDB 4.0) | Dates, times and intervals |
Interval | interval (SurrealDB 4.0) | Dates, times and intervals |
Regex | regex (SurrealDB 4.0) | Regex |
The SDK sends the SurrealDB 4.0 types as their own types only over cbor.2, the format that SurrealDB 4.0 servers speak. Against an earlier server, it sends the nearest type that the server has, and the page for each class says what that is. A datetime.timedelta and a compiled re.Pattern cannot be sent, and raise TypeError.
The Value type
Value is the union of the values that the SDK sends and reads back, and methods use it to annotate data and results. The Python types page explains it in full.
Value = (
str | int | float | bool | None | NullType
| bytes | UUID | Decimal
| Table | Range | RecordID | StringRecordId | File
| Duration | Datetime
| BigDecimal | PlainDate | PlainTime | Timestamp | Interval | Regex
| date | time
| GeometryPoint | GeometryLine | GeometryPolygon
| GeometryMultiPoint | GeometryMultiLine | GeometryMultiPolygon
| GeometryCollection
| SurrealSet | set[Any] | frozenset[Any]
| dict[str, "Value"] | list["Value"]
) RecordIdType
RecordIdType is the union that CRUD methods accept as a target. A str in it is always a table name. Import it from surrealdb.data.types.record_id; the RecordID page has the details.
RecordIdType = str | RecordID | StringRecordId | Table Tokens
Tokens is the frozen dataclass that signin() and signup() return, with an access token and an optional refresh token. It is documented with the other dataclasses on the Python types page.
See also
Value types for how values convert, with examples
Python types for type aliases, options and other dataclasses
Data types in SurrealQL