Skip to content

Python

Installation

This page shows how to install the Python SDK, choose its optional extras, and import it into a project. The SDK needs Python 3.10 or later.

Install the SurrealDB SDK from PyPI:

pip install surrealdb

With uv:

uv add surrealdb

To check the installed version:

pip show surrealdb

The default install connects to a remote SurrealDB instance over WebSocket or HTTP. It depends on websockets 15.0 or later, aiohttp 3.14.0 or later, requests and pydantic-core.

Three features ship as extras, so that a project installs only what it uses:

ExtraCommandWhat it adds
embeddedpip install "surrealdb[embedded]"The embedded engine, a native package called surrealdb-embedded that runs SurrealDB 4.0 in your process. It is needed for mem://, memory, file:// and surrealkv:// URLs. See Embedded databases.
pydanticpip install "surrealdb[pydantic]"Validation and serialisation of RecordID and StringRecordId fields in pydantic models.
memorypip install "surrealdb[memory]"The Agent Memory client, imported from surrealdb.memory.

With uv, use the same names: uv add "surrealdb[embedded]". To install more than one extra, separate them with commas: pip install "surrealdb[embedded,pydantic]".

Without the embedded extra, an embedded URL raises UnsupportedEngineError with the command to install it. The embedded engine has prebuilt wheels for macOS on Intel and Apple silicon, Linux on x86-64 and ARM64 (glibc and musl), and Windows on x86-64. On other platforms, pip builds it from source, which needs Rust 1.95 or later.

The SDK has a factory function for each style of code. For blocking code, such as scripts and command-line tools:

from surrealdb import Surreal

For applications that use asyncio:

from surrealdb import AsyncSurreal

Both take a connection URL and return the connection class for its scheme. The value types, such as RecordID and Table, and the error classes are exported from surrealdb too:

from surrealdb import AsyncSurreal, RecordID, SurrealError, Table

Was this page helpful?