Skip to main content

A library to connect to SurrealDB.

Project description

PySurrealDB

An unofficial library to connect to SurrealDB.

Minimal dependancies, 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')

To connect to a live SurrealDB server, you can specify the 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')

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",
        }
    }
}

# 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()

This project is a work in progress. Please email aurelion314@gmail.com if you have any questions or feedback. 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.2.0.tar.gz (10.7 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.2.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for PySurrealDB-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2ef0b5e78e44171dba09020accb1a04958eae8435309bba8f57cbb393afeff10
MD5 3cb893010b1d70ce589856beeafef266
BLAKE2b-256 dfe4efc94f622434770ca181ddfb4d187f5d60c97587339630fe2c244bd5324a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PySurrealDB-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83cdf77fab314ee62257c97efeab5fe9ee0b2c44fa5605ccda9bf77c15c996d7
MD5 175118c3f0b774061a7ab747a01b1f6a
BLAKE2b-256 8096d82f8a13e6d4107da4ac8d66606043fc4b3ea34eabe20f5df328d36f604c

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