RecordID

A RecordID represents a unique record identifier in SurrealDB, combining a table name with an ID value. It is the Python equivalent of SurrealDB's record type.

Import

from surrealdb import RecordID

Source: record_id.py

Constructor

Syntax

RecordID(table_name, identifier)
ParameterTypeDescription
table_name strThe name of the table this record belongs to.
identifier AnyThe unique identifier for the record within the table.

Examples

String ID

record = RecordID("users", "john")

Numeric ID

record = RecordID("products", 42)

List ID

record = RecordID("events", ["2025", "01", "01"])

Static Methods

RecordID.parse()

Parses a record ID from its string representation.

Syntax

RecordID.parse(record_str)
ParameterTypeDescription
record_str strA record ID string in table_name:id format.

Returns: RecordID

record = RecordID.parse("users:john")
print(record.table_name) # "users"
print(record.id) # "john"

Properties

PropertyTypeDescription
table_namestrThe table name component of the record ID.
idValueThe identifier component of the record ID.
record = RecordID("users", "john")
print(record.table_name) # "users"
print(record.id) # "john"

Methods

__str__()

Returns the string representation in table_name:id format.

record = RecordID("users", "john")
print(str(record)) # "users:john"

__eq__()

Compares two RecordID instances for equality based on both table_name and id.

a = RecordID("users", "john")
b = RecordID("users", "john")
print(a == b) # True

Pydantic Support

When the pydantic extra is installed (pip install surrealdb[pydantic]), RecordID can be used as a field type in Pydantic models with automatic validation and serialization.

from pydantic import BaseModel
from surrealdb import RecordID

class User(BaseModel):
id: RecordID
name: str

user = User(id=RecordID("users", "john"), name="John")

RecordIdType

Methods that accept a record or table reference use the RecordIdType alias, which accepts a plain string, a Table, or a RecordID.

Type Definition

RecordIdType = str | Table | RecordID

See the Data Types overview for details.

See Also