A supercharged SQLite library for Python

Overview
supersqlite

SuperSQLite: a supercharged SQLite library for Python

pipeline status   Build Status   Build status
PyPI version   license   Python version

A feature-packed Python package and for utilizing SQLite in Python by Plasticity. It is intended to be a drop-in replacement to Python's built-in SQLite API, but without any limitations. It offers unique features like remote streaming over HTTP and bundling of extensions like JSON, R-Trees (geospatial indexing), and Full Text Search. SuperSQLite is also packaged with pre-compiled native binaries for SQLite and all of its extensions for nearly every platform as to avoid any C/C++ compiler errors during install.

Table of Contents

Installation

You can install this package with pip:

pip install supersqlite # Python 2.7
pip3 install supersqlite # Python 3

Motivation

SQLite, is a fast, popular embedded database, used by large enterprises. It is the most widely-deployed database and has billions of deployments. It has a built-in binding in Python.

The Python bindings, however, often are compiled against an out-of-date copy of SQLite or may be compiled with limitations set to low levels. Moreover, it is difficult to load extremely useful extensions like JSON1 that adds JSON functionality to SQLite or FTS5 that adds full-text search functionality to SQLite since they must be compiled with a C/C++ compiler on each platform before being loaded.

SuperSQLite aims to solve these problems by packaging a newer version of SQLite natively pre-compiled for every platform along with natively pre-compiled SQLite extensions. SuperSQLite also adds useful unique new features like remote streaming over HTTP to read from a centralized SQLite database.

Moreover, by default, SQLite does not enable some optimizations that can result in speedups. SuperSQLite compiles SQLite with various optimizations and allows you to select your workload at runtime to further automatically configure the connection to be optimized for your workload.

When to use SuperSQLite?

SQLite is extremely reliable and durable for large amounts of data (up to 140TB). It is considered one of the most well-engineered and well-tested software solutions today, with 711x more test code than implementation code.

SQLite is faster than nearly every other database at read-heavy use cases (especially compared to databases that may use a client-server model with network latency like MySQL, PostgreSQL, MongoDB, DynamoDB, etc.). You can also instantiate SQLite completely in-memory to remove disk latency, if your data will fit within RAM. For key/value use cases, you can get comparable or better read/write performance to key/value databases like LevelDB with the LSM1 extension.

When you have a write-heavy workload with multiple servers that need to write concurrently to a shared database (backend to a website), you would probably want to choose something that has a client-server model instead like PostgreSQL, although SQLite can handle processing write requests fast enough that it is sufficient for most concurrent write loads. In fact, Expensify uses SQLite for their entire backend. If you need the database to be automatically replicated or automatically sharded across machines or other distributed features, you probably want to use something else.

See Appropriate Uses For SQLite for more information and Well-Known Users of SQLite for example use cases.

Using the Library

Instead of 'import sqlite3', use:

from supersqlite import sqlite3

This retains compatibility with the sqlite3 package, while adding the various enhancements.

Connecting

Given the above import, connect to a sqlite database file using:

conn = sqlite3.connect('foo.db')

Querying

Remote Streaming over HTTP

Workload Optimizations

Extensions

JSON1

FTS3, FTS4, FTS5

LSM1

R*Tree

Other

Custom

Export SQLite Resources

Optimizations

Other Documentation

SuperSQLite extends the apsw Python SQLite wrapper and adds on to its functionality. You can find the full documentation for that library here, which in turn attempts to implement PEP 249 (DB API). The connection object, cursor object, etc. are all apsw.Connection, apsw.Cursor. Note, however, that some monkey-patching has been done to make the library more in-line and compatible as a drop-in replacement for Python's built-in sqlite3 module.

Other documentation is not available at this time. See the source file directly (it is well commented) if you need more information about a method's arguments or want to see all supported features.

Other Programming Languages

Currently, this library only supports Python. There are no plans to port it to any other languages, but since SQLite has a native C implementation and has bindings in most languages, you can use the export functions to load SuperSQLite's SQLite extensions in the SQLite bindings of other programming languages or link SuperSQLite's version of SQLite to a native binary.

Contributing

The main repository for this project can be found on GitLab. The GitHub repository is only a mirror. Pull requests for more tests, better error-checking, bug fixes, performance improvements, or documentation or adding additional utilties / functionalities are welcome on GitLab.

You can contact us at [email protected].

Roadmap

  • Out of the box, "fast-write" configuration option that makes the connection optimized for fast-writing.
  • Out of the box, "fast-read" configuration option that makes the conenction optimized for fast-reading.
  • Optimize streaming cache behavior

Other Notable Projects

  • pysqlite - The built-in sqlite3 module in Python.
  • apsw - Powers the main API of SuperSQLite, aims to port all of SQLite's API functionality (like VFSes) to Python, not just the query APIs.
  • Magnitude - Another project by Plasticity that uses SuperSQLite's unique features for machine learning embedding models.

LICENSE and Attribution

This repository is licensed under the license found here.

The SQLite "feather" icon is taken from the SQLite project which is released as public domain.

This project is not affiliated with the official SQLite project.

Comments
  • Missing __enter__() with cursor

    Missing __enter__() with cursor

    The syntax : with conn.cursor() as cursor: ... work with standard Python SQLite and others database drivers (postgres, ...) But the method __enter__() is not defined in supersqlite driver.

    opened by pprados 0
  • AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

    AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'

    Is supersqlite enable loading sqlite extensions? What can cause this error:

    from supersqlite import sqlite3 as sqlite33 conn33=sqlite33.connect("mydbfile.db") conn33.enable_load_extension(True) Traceback (most recent call last): File "", line 1, in AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension' thank you.

    opened by dbricker-intel 0
  • Publish supersqlite on conda-forge

    Publish supersqlite on conda-forge

    It would be very convenient to have this library available on conda-forge so it could be installed with the Conda package manager, which is ideal for packages with binary dependencies. Is that a possibility?

    opened by JWCook 0
  • No module named 'supersqlite.third_party.internal.apsw'

    No module named 'supersqlite.third_party.internal.apsw'

    Hello, I try to install supersqlite from pip and conda. I can use

    docker run -it ubuntu
    # then
    apt-get update ; \
    apt-get install -y python-apsw python3 python3-pip ; \
    pip3 install supersqlite ; python3 -c "import supersqlite"
    

    It's correct.

    Now, I try with conda

    docker run -it conda/miniconda3
    # Then
    conda update conda -y ; \
    conda init bash ;
    exec bash
    # and
    conda install -c conda-forge apsw -y ; \
    pip3 install supersqlite ; \
    python3 -c "import supersqlite"
    

    I receive and error: ModuleNotFoundError: No module named 'supersqlite.third_party.internal.apsw'

    Collecting supersqlite
      Downloading supersqlite-0.0.78.tar.gz (25.8 MB)
         |████████████████████████████████| 25.8 MB 3.9 MB/s 
    Building wheels for collected packages: supersqlite
      Building wheel for supersqlite (setup.py) ... done
      Created wheel for supersqlite: filename=supersqlite-0.0.78-cp39-cp39-linux_x86_64.whl size=71094064 sha256=64d23d0848fba148a4506b0905135d23df4d7099660bbba683584b71623d38a2
      Stored in directory: /root/.cache/pip/wheels/c2/83/40/cffebda33928fae730f81985e5d75078d257db3586bd419905
    Successfully built supersqlite
    Installing collected packages: supersqlite
    Successfully installed supersqlite-0.0.78
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/local/lib/python3.9/site-packages/supersqlite/__init__.py", line 47, in <module>
        import supersqlite.third_party.internal.apsw as apsw
    ModuleNotFoundError: No module named 'supersqlite.third_party.internal.apsw'
    

    You can reproduce this bug with this docker file

    # SuperSqliteDockerfile file
    FROM continuumio/anaconda3
    
    RUN conda create --name testSupersqlite python=3.7 ; \
        conda activate testSupersqlite ; \
        pip3 install supersqlite
    
    ENTRYPOINT python -c "import supersqlite"
    

    and

    docker run --rm -it $(docker build -q -f SuperSqliteDockerfile .)
    

    How can I resolve this problem?

    Thanks

    opened by pprados 1
  • Fix typo that causes install to break

    Fix typo that causes install to break

    pip install of supersqlite is broken due to a typo in a requirement name: lsb-db should actually be lsm-db.

    This also resolves https://github.com/plasticityai/supersqlite/issues/5

    opened by DDevine 2
  • [BUG] Outdated/typo in requirements.txt

    [BUG] Outdated/typo in requirements.txt

    Description

    It seems current requirements.txt is either outdated or contains a typo in https://github.com/plasticityai/supersqlite/blob/d74da749c6fa5df021df3968b854b9a59f829e17/requirements.txt#L1 When trying to pip install lsb-db==0.6.4 I get following error

    Could not find a version that satisfies the requirement lsb-db==0.6.4 (from versions: none)
    

    I guess this could be a typo for lsm-db?

    Expected behavior

    Installing this package via pip won't fail

    System

    Ubuntu 18.04LTS / Python 3.6 / pip 19.1.1

    cc @AjayP13

    opened by johnygomez 0
Releases(0.0.78)
Owner
Plasticity
The official GitHub account of Plasticity
Plasticity
PostgreSQL database access simplified

Queries: PostgreSQL Simplified Queries is a BSD licensed opinionated wrapper of the psycopg2 library for interacting with PostgreSQL. The popular psyc

Gavin M. Roy 251 Oct 25, 2022
Google Sheets Python API v4

pygsheets - Google Spreadsheets Python API v4 A simple, intuitive library for google sheets which gets your work done. Features: Open, create, delete

Nithin Murali 1.4k Dec 31, 2022
A fast PostgreSQL Database Client Library for Python/asyncio.

asyncpg -- A fast PostgreSQL Database Client Library for Python/asyncio asyncpg is a database interface library designed specifically for PostgreSQL a

magicstack 5.8k Dec 31, 2022
Python DBAPI simplified

Facata A Python library that provides a simplified alternative to DBAPI 2. It provides a facade in front of DBAPI 2 drivers. Table of Contents Install

Tony Locke 44 Nov 17, 2021
Python PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.

Python PG Extras Python port of Heroku PG Extras with several additions and improvements. The goal of this project is to provide powerful insights int

Paweł Urbanek 35 Nov 01, 2022
A Redis client library for Twisted Python

txRedis Asynchronous Redis client for Twisted Python. Install Install via pip. Usage examples can be found in the examples/ directory of this reposito

Dorian Raymer 127 Oct 23, 2022
A tool to snapshot sqlite databases you don't own

The core here is my first attempt at a solution of this, combining ideas from browser_history.py and karlicoss/HPI/sqlite.py to create a library/CLI tool to (as safely as possible) copy databases whi

Sean Breckenridge 10 Dec 22, 2022
Google Cloud Client Library for Python

Google Cloud Python Client Python idiomatic clients for Google Cloud Platform services. Stability levels The development status classifier on PyPI ind

Google APIs 4.1k Jan 01, 2023
Pure Python MySQL Client

PyMySQL Table of Contents Requirements Installation Documentation Example Resources License This package contains a pure-Python MySQL client library,

PyMySQL 7.2k Jan 09, 2023
A collection of awesome sqlite tools, scripts, books, etc

Awesome Series @ Planet Open Data World (Countries, Cities, Codes, ...) • Football (Clubs, Players, Stadiums, ...) • SQLite (Tools, Books, Schemas, ..

Planet Open Data 205 Dec 16, 2022
Dlsite-doujin-renamer - Dlsite doujin renamer tool with python

dlsite-doujin-renamer Features 支持深度查找带有 RJ 号的文件夹 支持手动选择文件夹或拖拽文件夹到软件窗口 支持在 config

111 Jan 02, 2023
High level Python client for Elasticsearch

Elasticsearch DSL Elasticsearch DSL is a high-level library whose aim is to help with writing and running queries against Elasticsearch. It is built o

elastic 3.6k Jan 03, 2023
asyncio (PEP 3156) Redis support

aioredis asyncio (PEP 3156) Redis client library. Features hiredis parser Yes Pure-python parser Yes Low-level & High-level APIs Yes Connections Pool

aio-libs 2.2k Jan 04, 2023
A framework based on tornado for easier development, scaling up and maintenance

turbo 中文文档 Turbo is a framework for fast building web site and RESTFul api, based on tornado. Easily scale up and maintain Rapid development for RESTF

133 Dec 06, 2022
Making it easy to query APIs via SQL

Shillelagh Shillelagh (ʃɪˈleɪlɪ) is an implementation of the Python DB API 2.0 based on SQLite (using the APSW library): from shillelagh.backends.apsw

Beto Dealmeida 207 Dec 30, 2022
A HugSQL-inspired database library for Python

PugSQL PugSQL is a simple Python interface for using parameterized SQL, in files. See pugsql.org for the documentation. To install: pip install pugsql

Dan McKinley 558 Dec 24, 2022
aiomysql is a library for accessing a MySQL database from the asyncio

aiomysql aiomysql is a "driver" for accessing a MySQL database from the asyncio (PEP-3156/tulip) framework. It depends on and reuses most parts of PyM

aio-libs 1.5k Jan 03, 2023
ClickHouse Python Driver with native interface support

ClickHouse Python Driver ClickHouse Python Driver with native (TCP) interface support. Asynchronous wrapper is available here: https://github.com/myma

Marilyn System 957 Dec 30, 2022
A Pythonic, object-oriented interface for working with MongoDB.

PyMODM MongoDB has paused the development of PyMODM. If there are any users who want to take over and maintain this project, or if you just have quest

mongodb 345 Dec 25, 2022
A fast MySQL driver written in pure C/C++ for Python. Compatible with gevent through monkey patching.

:: Description :: A fast MySQL driver written in pure C/C++ for Python. Compatible with gevent through monkey patching :: Requirements :: Requires P

ESN Social Software 549 Nov 18, 2022