---
title: "Python"
description: "Embed SurrealDB 4.0 in a Python application with the surrealdb[embedded] extra of the Python SDK, using in-memory (mem://) or on-disk (surrealkv://, file://) storage without a separate server."
canonical_url: "https://surrealdb.com/docs/integrate/embedding/by-language/python"
section: "By language"
surrealdb_version: "4.x"
last_modified: "2026-11-18T02:09:16Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Python

Embed SurrealDB 4.0 in a Python application with the surrealdb[embedded] extra of the Python SDK, using in-memory (mem://) or on-disk (surrealkv://, file://) storage without a separate server.

The Python SDK can run SurrealDB inside your Python process, so that your application uses SurrealDB without a separate server. This suits desktop applications, tests, local development and programs that keep their data on the same machine. This page shows how to install the embedded engine and gives a short example. [Embedded databases](/docs/reference/python/concepts/embedded-databases.md) in the Python SDK documentation covers the rest, such as the features that an embedded connection supports and how to move data from an earlier engine.

## Install the embedded engine

The embedded engine is an optional part of the SDK, which the `embedded` extra installs:

```bash
pip install "surrealdb[embedded]"
```

## Embedded storage options

- **In memory** (`mem://` or `memory`): the data is kept in the memory of the process and is lost when the connection closes. This suits tests and temporary data.
- **On disk** (`surrealkv://` or `file://`): the data is kept in a SurrealKV directory, and it is still there when the program opens the directory again.

## Example

An embedded connection needs no sign-in, so call `use()` and start to query:

```python
import asyncio

from surrealdb import AsyncSurreal, Table


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

    # On-disk database in the directory mydb
    async with AsyncSurreal("surrealkv://mydb") as db:
        await db.use("main", "main")
        company = await db.create(Table("company"), {"name": "TechStart"})
        print(company)


asyncio.run(main())
```

The same code works with the blocking client: use `Surreal` in place of `AsyncSurreal`, `with` in place of `async with`, and leave out `await`.
