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.
from surrealdb import RecordIDSource: record_id.py
Constructor
RecordID(table_name, identifier)Parameter | Type | Description |
|---|---|---|
table_name | str | The name of the table this record belongs to. |
identifier | Any | The unique identifier for the record within the table. |
Examples
record = RecordID("users", "john")record = RecordID("products", 42)record = RecordID("events", ["2025", "01", "01"])Static methods
RecordID.parse()
Parses a record ID from its string representation.
RecordID.parse(record_str)Parameter | Type | Description |
|---|---|---|
record_str | str | A record ID string in table_name:idformat. |
Returns: RecordID
record = RecordID.parse("users:john")
print(record.table_name) # "users"
print(record.id) # "john"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) # "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) # TruePydantic 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.
RecordIdType = str | Table | RecordIDSee the Data types overview for details.
See also
Data types — All SDK data types
Table — Table name wrapper
Surreal — Connection and query methods