Skip to main content

A library to connect to SurrealDB.

Project description

PySurrealDB

Join the chat at https://gitter.im/pysurrealdb/community

An unofficial library to connect to SurrealDB.

Minimal dependencies, easy to use.


Getting Started

If you don't already have it, install SurrealDB

Linux:

$ curl -sSf https://install.surrealdb.com | sh
# then
$ surreal start --user test --pass test

Install PySurrealDB

pip install pysurrealdb

Examples

import pysurrealdb as surreal

conn = surreal.connect(user='test', password='test')

conn.create('person', {'name': 'Mike'})
conn.query('select * from person')

You can specify additional connection info either in the connect call, or in a config file.

import pysurrealdb as surreal
conn = surreal.connect(host='surreal.com', port=8000, user='user', password='pass', database='db', namespace='ns')

Both http and websocket are supported. Specify which to use with the client keyword.

conn = surreal.connect(client='websocket')
# Websocket was added and made the default as of version 0.3. Try http if you run into issues, and please report any bugs you find!

Optional Config file:

# use a configured connection. 
conn = surreal.connection('default')
# Requires pysurrealdb.json file. Place it in your root directory, or specify the file location with the env variable 'PYSURREALDB_CONFIG'.

Example pysurrealdb.json:
{
    "connections": {
        "default": {
            "host": "localhost",
            "port": 8000,
            "user": "test",
            "password": "test"
            "database": "test",
            "namespace": "test",
            "client": "http",
        }
    }
}

# when using a config file, you do not even need to connect, you can access most functions directly:
import pysurrealdb as surreal

surreal.query('select * from test') # uses the last connection from connect() or the default connection if connect() has not been called.

Query Builder

You can write queries using Laravel and Orator style syntax:

import pysurrealdb as surreal
conn = surreal.connection()

# setup data
conn.drop('person')
conn.insert('person', [{'name': 'Mike', 'age': 31}, {'name':'Mr P'}])

# query builder examples
first_person = conn.table('person').where('name', 'Mike').first()

adults = conn.table('person').where('age', '>=', 18).order_by('age', 'desc').limit(10).get()

Methods

Some of the basic methods available:

query(sql)
get(table, id='')
insert(table, data)
create(table, data)
update(table, data)
upsert(table, data)
delete(table, id)
drop(table)
relate(noun, verb, noun2, data={})

# Most methods accept a table or table:id as the main arguement. The data is also checked for an ID when relevant.

This project is a work in progress. Questions and feedback are welcome! Please create an issue or use the gitter chat link at the top. Thanks!

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

PySurrealDB-0.3.2.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

PySurrealDB-0.3.2-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file PySurrealDB-0.3.2.tar.gz.

File metadata

  • Download URL: PySurrealDB-0.3.2.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.2 Linux/5.15.0-60-generic

File hashes

Hashes for PySurrealDB-0.3.2.tar.gz
Algorithm Hash digest
SHA256 aafcbe0464031340990614f66cd520ecf0feac60fda1f2d5fb219b1e5d48af8b
MD5 b28c354ec64b82029bc8f34fe1d3c49d
BLAKE2b-256 2c29822592e7b05c9187bad6552cf05b6973a1ed294bc971d7177519a08a9fd3

See more details on using hashes here.

File details

Details for the file PySurrealDB-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: PySurrealDB-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.2 Linux/5.15.0-60-generic

File hashes

Hashes for PySurrealDB-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 75ef42a0b6792cbe3e495cfdfdfac1e2f1afb3668d3098d16d0383f0b16cc127
MD5 5d42b4633815cb08fea8e0923b589d4b
BLAKE2b-256 d4fcffaf7527e028888cc80421cb10bdef586dffd8d61f79698131ced9cd63ed

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