Skip to content

By language

Python

SurrealDB can be run as an embedded database within your Python application, allowing you to use SurrealDB without running a separate server process. This is ideal for desktop applications, testing, local development, and edge computing scenarios.

SurrealDB supports two types of embedded storage in Python:

  • In-memory database (mem:// or memory) - Fastest performance with data stored in RAM. Perfect for testing, caching, or temporary data. Data is lost when the connection closes.

  • File-based database (file://, rocksdb://, or surrealkv://) - Persistent storage on disk using the SurrealKV storage engine. Data persists across connections and application restarts.

from surrealdb import AsyncSurreal

# In-memory database
async with AsyncSurreal("mem://") as db:
    await db.use("main", "main")
    person = await db.create("person", {"name": "John Doe"})
    print(person)

# File (RocksDB)-based persistent database
async with AsyncSurreal("rocksdb://mydb") as db:
    await db.use("main", "main")
    company = await db.create("company", {"name": "TechStart"})
    print(company)

For complete documentation, installation instructions, examples, best practices, and troubleshooting, see the rest of this guide.

Was this page helpful?