Value types
The Python SDK maps SurrealDB data types to Python types automatically. Standard Python types like str, int, float, bool, None, dict, and list map directly to their SurrealDB equivalents. For SurrealDB-specific types such as record identifiers, durations, and geometry, the SDK provides dedicated Python classes.
See the Data Types reference for the full API details of each type.
API References
| Class |
|---|
RecordID(table_name, identifier) |
Table(table_name) |
Duration(elapsed) |
Datetime(dt) |
Range(begin, end) |
GeometryPoint(...) |
Type mapping between Python and SurrealDB
The following table shows how Python types correspond to SurrealDB types. Standard library types are used directly, while SurrealDB-specific types use the custom classes listed above.
| Python Type | SurrealDB Type |
|---|---|
str | string |
int | int |
float | float |
bool | bool |
None | NONE / NULL |
bytes | bytes |
UUID | uuid |
Decimal | decimal |
dict | object |
list | array |
RecordID | record |
Table | table |
Duration | duration |
Datetime | datetime |
Range | range |
Geometry* | geometry |
Working with record identifiers
A RecordID uniquely identifies a single record in a table by combining a table name with an identifier value. You can construct one directly or parse it from a string.
The identifier can be a string, integer, list, or any other supported value type. Use RecordID wherever the SDK expects a record reference, such as in .select(), .create(), or .delete().
See the RecordID reference for the complete API, including equality checks and Pydantic support.
Working with durations
A Duration represents a time span with nanosecond precision. The most common way to create one is by parsing a human-readable string using SurrealDB's duration syntax.
You can also construct a Duration directly from nanoseconds and convert it back to a string.
Durations are useful for setting intervals, timeouts, and TTLs in your data.
See the Duration reference for all unit properties and methods.
Working with datetime values
A Datetime wraps an ISO 8601 datetime string for use with SurrealDB's datetime type. It preserves the original string representation through serialization and deserialization.
Use Datetime when creating records that contain date or time fields.
See the Datetime reference for the full API.
Working with ranges
A Range represents a bounded interval with inclusive or exclusive endpoints. Each bound is wrapped in a BoundIncluded or BoundExcluded to specify whether the boundary value is part of the range.
Ranges are commonly used in query parameters to filter results within a specific interval.
See the Range reference for the full API and bound types.
Working with geometry types
The SDK provides seven GeoJSON-compatible geometry types for working with SurrealDB's spatial data: GeometryPoint, GeometryLine, GeometryPolygon, GeometryMultiPoint, GeometryMultiLine, GeometryMultiPolygon, and GeometryCollection.
The most common type is GeometryPoint, which represents a single geographic coordinate.
More complex types compose from simpler ones — a GeometryLine is built from a list of points, a GeometryPolygon from a list of lines, and so on. See the Geometry reference for constructors and examples of all seven types.
Learn more
Data Types reference for complete API details
RecordID reference for record identifier API
Duration reference for duration API
Python types for Value and RecordIdType definitions
Data manipulation for using types in queries