• Start

Languages

/

Python

/

API Reference

/

Values

RecordID

Record identifier with table name and ID components.

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

Syntax
RecordID(table_name, identifier)

Parameter

Type

Description

table_namestr

The name of the table this record belongs to.

identifierAny

The unique identifier for the record within the table.

String ID
record = RecordID("users", "john")
Numeric ID
record = RecordID("products", 42)
List ID
record = RecordID("events", ["2025", "01", "01"])

Parses a record ID from its string representation.

Syntax
RecordID.parse(record_str)

Parameter

Type

Description

record_strstr

A record ID string in

table_name:id

format.

Returns: RecordID

record = RecordID.parse("users:john")
print(record.table_name)  # "users"
print(record.id)          # "john"
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"

Returns the string representation in table_name:id format.

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

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

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")

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.

  • Data types — All SDK data types

  • Table — Table name wrapper

  • Surreal — Connection and query methods

Was this page helpful?