mcpField
S
surrealdb-python

surrealdb-python

github.com/surrealdbData & databases28432 installsUpdated 4w ago
Repository

About surrealdb-python

surrealdb-python is a Python SDK for working with SurrealDB. It supports server connections as well as embedded, in-process use with in-memory or file-based storage.

Key features

  1. 01Synchronous and asynchronous clients
  2. 02WebSocket server connections
  3. 03Embedded in-memory databases
  4. 04Embedded file-based persistence

Use cases

  1. 01Connect Python applications to a SurrealDB server
  2. 02Run SurrealDB inside a Python process
  3. 03Persist embedded database data to files

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/surrealdb/agent-skills --skill surrealdb-python

After installing, type/surrealdb-pythonin Claude Code to confirm it loaded.

Bundled filesreferences/embedded.md

Details

From the project README

SurrealDB Python SDK

Running SurrealDB (Server Mode)

Persist data with RocksDB:

surreal start -u root -p root rocksdb:database

In-memory:

surreal start -u root -p root

Client/Server Mode

Connect via WebSocket using the Surreal context manager:

from surrealdb import Surreal

with Surreal("ws://localhost:8000/rpc") as db:
    db.signin({"username": "root", "password": "root"})
    db.use("namespace_test", "database_test")

    db.create(
        "person",
        {
            "user": "me",
            "password": "safe",
            "marketing": True,
            "tags": ["python", "documentation"],
        },
    )

    print(db.select("person"))

    print(db.update("person", {
        "user": "you",
        "password": "very_safe",
        "marketing": False,
        "tags": ["Awesome"],
    }))

    print(db.delete("person"))

    db.query("""
    insert into person {
        user: 'me',
        password: 'very_safe',
        tags: ['python', 'documentation']
    };
    """)

    print(db.query("select * from person"))

    print(db.query("""
    update person content {
        user: 'you',
        password: 'more_safe',
        tags: ['awesome']
    };
    """))

    print(db.query("delete person"))

Embedded Mode

Run SurrealDB directly inside your Python process — no server required.

  • In-memory: Surreal("mem://") / AsyncSurreal("mem://")
  • File-based persistence: Surreal(f"file://{db_path}") / AsyncSurreal(f"file://{db_path}")

See references/embedded.md for a complete async example with file-based persistence.

Comments

Markdown supported