GitXplorerGitXplorer
s

surrealdb.py

public
178 stars
53 forks
26 issues

Commits

List of commits on branch main.
Unverified
ffefd8a2354ff597f6f18115d18fa4eab45d6540

Update README

ttobiemh committed 4 months ago
Unverified
496f8bebee49a54dccc2495ad4cdba1cd9a4776f

Improve README

ttobiemh committed 4 months ago
Unverified
db662017a33d8b44346efc864c3628dbaf91ff92

Update README

ttobiemh committed 4 months ago
Verified
bf1e1e9edadac19ef3791197e082faca6afe3729

Update examples, readme and remove old version (#92)

AAlexFrid committed 6 months ago
Verified
c8a4c84c5f2f6a940a874eaafcd40695b283a9a8

Updated code formatting and lint (latest `ruff`, `mypy`) (#91)

aalexander-beedie committed 6 months ago
Verified
7de2c20a2397ef90408d731ede32c4ea7830377f

Rust remove tokio (#76)

mmaxwellflitton committed 7 months ago

README

The README file for this repository.

 

The official SurrealDB SDK for Python.


       

     

surrealdb.py

The official SurrealDB SDK for Python.

Documentation

View the SDK documentation here.

How to install

pip install surrealdb

Getting started

Running within synchronous code

This example requires SurrealDB to be installed and running on port 8000.

Import the SDK and create the database connection:

from surrealdb import SurrealDB

db = SurrealDB("ws://localhost:8000/database/namespace")

Here, we can see that we defined the connection protocol as WebSocket using ws://. We then defined the host as localhost and the port as 8000.

Finally, we defined the database and namespace as database and namespace. We need a database and namespace to connect to SurrealDB.

Now that we have our connection we need to signin:

db.signin({
    "username": "root",
    "password": "root",
})

We can now run our queries to create some users, select them and print the outcome.

db.query("CREATE user:tobie SET name = 'Tobie';")
db.query("CREATE user:jaime SET name = 'Jaime';")
outcome = db.query("SELECT * FROM user;")
print(outcome)

Running within asynchronous code

This example requires SurrealDB to be installed and running on port 8000.

The async methods work in the same way, with two main differences:

  • Inclusion of async def / await.
  • You need to call the connect method before signing in.
import asyncio
from surrealdb import AsyncSurrealDB

async def main():
    db = AsyncSurrealDB("ws://localhost:8000/database/namespace")
    await db.connect()
    await db.signin({
        "username": "root",
        "password": "root",
    })
    await db.query("CREATE user:tobie SET name = 'Tobie';")
    await db.query("CREATE user:jaime SET name = 'Jaime';")
    outcome = await db.query("SELECT * FROM user;")
    print(outcome)


# Run the main function
asyncio.run(main())

Using Jupyter Notebooks

The Python SDK currently only supports the AsyncSurrealDB methods.