Skip to main content

SurrealDB python client written in Rust.

Project description

SurrealDB Icon


SurrealDB Logo SurrealDB Logo

SurrealDB SurrealDB is the ultimate cloud
database for tomorrow's applications

Develop easier.   Build faster.   Scale quicker.


         

Blog   Github	  LinkedIn   Twitter   Youtube   Dev   Discord   StackOverflow

surrealdb.py

The official SurrealDB SDK for Python.

See the documentation here

Getting Started

Below is a quick guide on how to get started with SurrealDB in Python.

Running SurrealDB

Before we can do anything, we need to download SurrealDB and start the server. See how to do that here

After we have everything up and running, we can install the Python SDK.

Installing the Python SDK

pip install surrealdb

Using the (synchronous) Python methods

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)

Using the async Python methods

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-beta-0.0.5.tar.gz (16.5 kB view hashes)

Uploaded Source

Built Distributions

surrealdb_beta-0.0.5-pp39-pypy39_pp73-win_amd64.whl (11.7 MB view hashes)

Uploaded PyPy Windows x86-64

surrealdb_beta-0.0.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

surrealdb_beta-0.0.5-pp39-pypy39_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (13.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

surrealdb_beta-0.0.5-pp39-pypy39_pp73-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

surrealdb_beta-0.0.5-pp38-pypy38_pp73-win_amd64.whl (11.7 MB view hashes)

Uploaded PyPy Windows x86-64

surrealdb_beta-0.0.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

surrealdb_beta-0.0.5-pp38-pypy38_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (13.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

surrealdb_beta-0.0.5-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

surrealdb_beta-0.0.5-pp37-pypy37_pp73-win_amd64.whl (11.7 MB view hashes)

Uploaded PyPy Windows x86-64

surrealdb_beta-0.0.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

surrealdb_beta-0.0.5-pp37-pypy37_pp73-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (13.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

surrealdb_beta-0.0.5-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

surrealdb_beta-0.0.5-cp310-cp310-win_amd64.whl (11.7 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

surrealdb_beta-0.0.5-cp310-cp310-win32.whl (10.6 MB view hashes)

Uploaded CPython 3.10 Windows x86

surrealdb_beta-0.0.5-cp310-cp310-musllinux_1_1_x86_64.whl (12.9 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

surrealdb_beta-0.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

surrealdb_beta-0.0.5-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (13.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

surrealdb_beta-0.0.5-cp310-cp310-macosx_11_0_arm64.whl (11.3 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

surrealdb_beta-0.0.5-cp310-cp310-macosx_10_9_x86_64.whl (12.0 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

surrealdb_beta-0.0.5-cp310-cp310-macosx_10_9_universal2.whl (23.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

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