Skip to main content

The official SurrealDB library for Python.

Project description


 

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

surrealdb-0.4.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

surrealdb-0.4.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file surrealdb-0.4.0.tar.gz.

File metadata

  • Download URL: surrealdb-0.4.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.0.0

File hashes

Hashes for surrealdb-0.4.0.tar.gz
Algorithm Hash digest
SHA256 54ee5d39182053167b5be7953665eee267e7685e9e8e3915b9d7a52c55da39fc
MD5 58b4a9753b4e75f73fef94987fa42cf8
BLAKE2b-256 e5b2c5af1c971171b95bc06f4285062b7940a4329f7e86dde9f0191a3903cbbf

See more details on using hashes here.

File details

Details for the file surrealdb-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: surrealdb-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.0.0

File hashes

Hashes for surrealdb-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe7ee1bdece2bc37b2193a6e89664b148e9e5734d97a545a317056fcf653e94
MD5 ff39f7323a8539f0966c5f933daf9a2c
BLAKE2b-256 2f58da96f2f2a12f2d07f2f6a2a11eea8d5956eb8e2fa7502cc33afae133e19e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page