All Projects → RaRe-Technologies → Sqlitedict

RaRe-Technologies / Sqlitedict

Licence: apache-2.0
Persistent dict, backed by sqlite3 and pickle, multithread-safe.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Sqlitedict

Zblogphp
Z-BlogPHP博客程序
Stars: ✭ 527 (-17.78%)
Mutual labels:  sqlite
Javamtp
《Java多线程编程实战指南(设计模式篇)》源码
Stars: ✭ 575 (-10.3%)
Mutual labels:  multi-threading
H2o 3
H2O is an Open Source, Distributed, Fast & Scalable Machine Learning Platform: Deep Learning, Gradient Boosting (GBM) & XGBoost, Random Forest, Generalized Linear Modeling (GLM with Elastic Net), K-Means, PCA, Generalized Additive Models (GAM), RuleFit, Support Vector Machine (SVM), Stacked Ensembles, Automatic Machine Learning (AutoML), etc.
Stars: ✭ 5,656 (+782.37%)
Mutual labels:  multi-threading
Sqlitedb
Basic SQLite wrapper for Swift 4.x and lightweight ORM for accessing underlying tables in an SQLite database
Stars: ✭ 538 (-16.07%)
Mutual labels:  sqlite
Jvedio
Windows desktop application to manage local video;Support baidu AI, youdao translation;Support FFMPEG video processing;Support multi-database management and statistics;Support skin switching
Stars: ✭ 545 (-14.98%)
Mutual labels:  sqlite
Sqlite3 Ruby
Ruby bindings for the SQLite3 embedded database
Stars: ✭ 592 (-7.64%)
Mutual labels:  sqlite
Tuql
Automatically create a GraphQL server from a SQLite database or a SQL file
Stars: ✭ 526 (-17.94%)
Mutual labels:  sqlite
Easydb
Easy-to-use PDO wrapper for PHP projects.
Stars: ✭ 624 (-2.65%)
Mutual labels:  sqlite
Csvs To Sqlite
Convert CSV files into a SQLite database
Stars: ✭ 568 (-11.39%)
Mutual labels:  sqlite
Sqlitebiter
A CLI tool to convert CSV / Excel / HTML / JSON / Jupyter Notebook / LDJSON / LTSV / Markdown / SQLite / SSV / TSV / Google-Sheets to a SQLite database file.
Stars: ✭ 601 (-6.24%)
Mutual labels:  sqlite
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-15.91%)
Mutual labels:  sqlite
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+4043.37%)
Mutual labels:  sqlite
Whc modelsqlitekit
专业的ORM数据库操作开源库,线程安全,高性能模型对象存储Sqlite开源库,真正实现一行代码操作数据库,让数据库存储变得简单 Professional database storage solutions, thread safe, high-performance model object storage Sqlite open source library, realize one line of code database operation, simple database storage
Stars: ✭ 597 (-6.86%)
Mutual labels:  sqlite
Datasette
An open source multi-tool for exploring and publishing data
Stars: ✭ 5,640 (+779.88%)
Mutual labels:  sqlite
Beekeeper Studio
Modern and easy to use SQL client for MySQL, Postgres, SQLite, SQL Server, and more. Linux, MacOS, and Windows.
Stars: ✭ 8,053 (+1156.32%)
Mutual labels:  sqlite
Sqlitecodefirst
Creates a SQLite Database based on a EdmModel by using Entity Framework CodeFirst.
Stars: ✭ 526 (-17.94%)
Mutual labels:  sqlite
Taskflow
A General-purpose Parallel and Heterogeneous Task Programming System
Stars: ✭ 6,128 (+856.01%)
Mutual labels:  multi-threading
Node Sqlite
SQLite client for Node.js applications with SQL-based migrations API written in Typescript
Stars: ✭ 642 (+0.16%)
Mutual labels:  sqlite
Rezoom.sql
Statically typechecks a common SQL dialect and translates it to various RDBMS backends
Stars: ✭ 621 (-3.12%)
Mutual labels:  sqlite
Daff
align and compare tables
Stars: ✭ 598 (-6.71%)
Mutual labels:  sqlite

================================================================= sqlitedict -- persistent dict, backed-up by SQLite and pickle

|Travis|_ |License|_

.. |Travis| image:: https://travis-ci.org/RaRe-Technologies/sqlitedict.svg?branch=master .. |Downloads| image:: https://img.shields.io/pypi/dm/sqlitedict.svg .. |License| image:: https://img.shields.io/pypi/l/sqlitedict.svg .. _Travis: https://travis-ci.org/RaRe-Technologies/sqlitedict .. _Downloads: https://pypi.python.org/pypi/sqlitedict .. _License: https://pypi.python.org/pypi/sqlitedict

A lightweight wrapper around Python's sqlite3 database with a simple, Pythonic dict-like interface and support for multi-thread access:

.. code-block:: python

from sqlitedict import SqliteDict mydict = SqliteDict('./my_db.sqlite', autocommit=True) mydict['some_key'] = 'any_picklable_object' print(mydict['some_key']) # prints the new value any_picklable_object for key, value in mydict.iteritems(): ... print(key, value) some_key any_picklable_object print(len(mydict)) # etc... all dict functions work 1 mydict.close()

Pickle is used internally to (de)serialize the values. Keys are arbitrary strings, values arbitrary pickle-able objects.

If you don't use autocommit (default is no autocommit for performance), then don't forget to call mydict.commit() when done with a transaction:

.. code-block:: python

using SqliteDict as context manager works too (RECOMMENDED)

with SqliteDict('./my_db.sqlite') as mydict: # note no autocommit=True ... mydict['some_key'] = u"first value" ... mydict['another_key'] = range(10) ... mydict.commit() ... mydict['some_key'] = u"new value" ... # no explicit commit here with SqliteDict('./my_db.sqlite') as mydict: # re-open the same DB ... print(mydict['some_key']) # outputs 'first value', not 'new value' first value

Features

  • Values can be any picklable objects (uses cPickle with the highest protocol).

  • Support for multiple tables (=dicts) living in the same database file.

  • Support for access from multiple threads to the same connection (needed by e.g. Pyro). Vanilla sqlite3 gives you ProgrammingError: SQLite objects created in a thread can only be used in that same thread.

    Concurrent requests are still serialized internally, so this "multithreaded support" doesn't give you any performance benefits. It is a work-around for sqlite limitations in Python.

  • Support for custom serialization or compression:

.. code-block:: python

use JSON instead of pickle

import json mydict = SqliteDict('./my_db.sqlite', encode=json.dumps, decode=json.loads)

apply zlib compression after pickling

import zlib, pickle, sqlite3 def my_encode(obj): ... return sqlite3.Binary(zlib.compress(pickle.dumps(obj, pickle.HIGHEST_PROTOCOL))) def my_decode(obj): ... return pickle.loads(zlib.decompress(bytes(obj))) mydict = SqliteDict('./my_db.sqlite', encode=my_encode, decode=my_decode)

Installation

The module has no dependencies beyond Python itself. The minimum Python version is 2.5, continuously tested on Python 2.7, and above on on Github Actions <https://github.com/RaRe-Technologies/sqlitedict/actions>_.

Install or upgrade with::

pip install -U sqlitedict

or from the source tar.gz <http://pypi.python.org/pypi/sqlitedict>_::

python setup.py install

Documentation

Standard Python document strings are inside the module:

.. code-block:: python

import sqlitedict help(sqlitedict)

(but it's just dict with a commit, really).

Beware: because of Python semantics, sqlitedict cannot know when a mutable SqliteDict-backed entry was modified in RAM. For example, mydict.setdefault('new_key', []).append(1) will leave mydict['new_key'] equal to empty list, not [1]. You'll need to explicitly assign the mutated object back to SqliteDict to achieve the same effect:

.. code-block:: python

val = mydict.get('new_key', []) val.append(1) # sqlite DB not updated here! mydict['new_key'] = val # now updated

For developers

Install::

# pip install pytest coverage pytest-coverage

To perform all tests::

# mkdir -p tests/db
# pytest tests

To perform all tests with coverage::

# pytest tests --cov=sqlitedict

Comments, bug reports

sqlitedict resides on github <https://github.com/RaRe-Technologies/sqlitedict>_. You can file issues or pull requests there.

Housekeeping

.. code-block:: python

import os os.unlink('my_db.sqlite')


sqlitedict is open source software released under the Apache 2.0 license <http://opensource.org/licenses/apache2.0.php>. Copyright (c) 2011-now Radim Řehůřek <http://radimrehurek.com> and contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].