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)
| Parameter | Type | Description |
|---|
table_name required | str | The name of the table this record belongs to. |
identifier required | Any | The 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)
| Parameter | Type | Description |
|---|
record_str required | str | A record ID string in table_name:id format. |
Returns: RecordID
record = RecordID.parse("users:john")
print(record.table_name)
print(record.id)
Properties
| Property | Type | Description |
|---|
table_name | str | The table name component of the record ID. |
id | Value | The identifier component of the record ID. |
record = RecordID("users", "john")
print(record.table_name)
print(record.id)
Methods
__str__()
Returns the string representation in table_name:id format.
record = RecordID("users", "john")
print(str(record))
__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)
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