Skip to main content

SurrealDB python client

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

Quick start

In this short guide, you will learn how to install, import, and initialize the SDK, as well as perform the basic data manipulation queries. This guide uses the Surreal class, but this example would also work with AsyncSurreal class, with the addition of await in front of the class methods.

Install

pip install surrealdb

Learn the basics

# Import the Surreal class
from surrealdb import Surreal

# Using a context manger to automatically connect and disconnect
with Surreal("ws://localhost:8000/rpc") as db:
    db.signin({"username": 'root', "password": 'root'})
    db.use("namepace_test", "database_test")

    # Create a record in the person table
    db.create(
        "person",
        {
            "user": "me",
            "password": "safe",
            "marketing": True,
            "tags": ["python", "documentation"],
        },
    )

    # Read all the records in the table
    print(db.select("person"))

    # Update all records in the table
    print(db.update("person", {
        "user":"you",
        "password":"very_safe",
        "marketing": False,
        "tags": ["Awesome"]
    }))

    # Delete all records in the table
    print(db.delete("person"))

    # You can also use the query method 
    # doing all of the above and more in SurrealQl
    
    # In SurrealQL you can do a direct insert 
    # and the table will be created if it doesn't exist
    
    # Create
    db.query("""
    insert into person {
        user: 'me',
        password: 'very_safe',
        tags: ['python', 'documentation']
    };
    """)

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

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

Next steps

Now that you have learned the basics of the SurrealDB SDK for Python, you can learn more about the SDK and its methods in the methods section and data types section.

Contributing

Contributions to this library are welcome! If you encounter issues, have feature requests, or want to make improvements, feel free to open issues or submit pull requests.

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-1.0.0b1.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

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

surrealdb-1.0.0b1-py2.py3-none-any.whl (40.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file surrealdb-1.0.0b1.tar.gz.

File metadata

  • Download URL: surrealdb-1.0.0b1.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for surrealdb-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 09060746081a3d8fba6cf24a8524e81f600b217d0c4178ed6349243f0713483d
MD5 185901759da2068cefeb54c41f55f478
BLAKE2b-256 b97493fd5fedb20af26771efcf74e3a5bb16e1042efd9b941ead50c615cffd1a

See more details on using hashes here.

File details

Details for the file surrealdb-1.0.0b1-py2.py3-none-any.whl.

File metadata

  • Download URL: surrealdb-1.0.0b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.1.0

File hashes

Hashes for surrealdb-1.0.0b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b678226f5ad00d654999638f5d54a2e7f32deeaa7edee4d06f4271f500b272a3
MD5 b89f290c2f81fbbcd88080e4c8ffd58c
BLAKE2b-256 22bed32554b01cc4f0e3ea19c138863ddb52356a5e9920511cb61b990b5bcadc

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