Giter VIP home page Giter VIP logo

sqlite_rx's Introduction

sqlite_rx

PyPI version sqlite-rx Downloads

Python 3.8 Python 3.9 Python 3.10 Python 3.11 Python 3.12

PyPy3.8 PyPy3.9

For documentation, usage and examples refer https://aosingh.github.io/sqlite_rx/

Introduction

SQLite is a lightweight database written in C. Python has in-built support to interact with the database (locally) which is either stored on disk or in memory.

With sqlite_rx, clients should be able to communicate with an SQLiteServer in a fast, simple and secure manner and execute queries remotely.

Key Features

Install

pip install -U sqlite_rx

Server

SQLiteServer runs in a single thread and follows an event-driven concurrency model (using tornado's event loop) which minimizes the cost of concurrent client connections. Following snippet shows how you can start the server process.

# server.py

from sqlite_rx.server import SQLiteServer

def main():

    # database is a path-like object giving the pathname 
    # of the database file to be opened. 
    
    # You can use ":memory:" to open a database connection to a database 
    # that resides in RAM instead of on disk

    server = SQLiteServer(database=":memory:",
                          bind_address="tcp://127.0.0.1:5000")
    server.start()
    server.join()

if __name__ == '__main__':
    main()

Client

The following snippet shows how you can instantiate an SQLiteClient and execute a simple CREATE TABLE query.

# client.py

from sqlite_rx.client import SQLiteClient

client = SQLiteClient(connect_address="tcp://127.0.0.1:5000")

with client:
  query = "CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)"
  result = client.execute(query)
>> python client.py

{'error': None, 'items': []}

sqlite_rx's People

Contributors

aosingh avatar marekyggdrasil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sqlite_rx's Issues

Feature suggestion: automated db backup

I think it would be really useful to be able to make db backups without killing the server process. It would be nice if backup could be scheduled using something like https://github.com/dbader/schedule and performed without breaking connections from the clients. My idea is, if client runs a query while backup is performed server would still notify the client of this so that the client could properly handle such exception.

I have a Python script that backs up the sqlite DB, if you find this idea appealing how about we join forces @aosingh ? If not, maybe you could give some hints what is the best way to manage backups under sqlite_rx setup.

Thanks in advance!

Won't start inside Jupyter Lab

This is what I get when starting the server within Jupyter Lab:

server = SQLiteServer(database=":memory:",
    bind_address="tcp://127.0.0.1:5003")
server.start()

Process SQLiteServer-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/xxxxxxx/lib/python3.6/site-packages/sqlite_rx/server.py", line 179, in run
    self.loop.start()
  File "/home/xxxxxxx/lib/python3.6/site-packages/tornado/platform/asyncio.py", line 149, in start
    self.asyncio_loop.run_forever()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 429, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

It appears that the process that SQLiteServer creates is not properly isolated from the calling process. Jupyter already starts an asyncio loop in the ipython kernel and SQLiteServer is seeing it, referencing it and not starting a new one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.