Skip to main content

Simple key-value cache for Python3 using SQLite3.

Project description

lite-cache

PyPi version codecov Supported Python versions License: GPL v3

Branch Build Status
master CircleCI
develop CircleCI

Simple sqlite key-value storage for Python3.

Python3 module for caching data during a program's runtime, with optional persistence.

Features

  • Program specific cache.
  • Simple encoding of data using standard json package.
  • Optional persistence of data across multiple executions.
    • Useful for keeping some runtime data available to a program after a full exit.
      • ex. raise Exception or sys.exit(), etc

Installation (from PyPI, with PIP)

lite-cache requires Python >= 3.6.

  1. If not already installed, install pip for Python 3
  2. Install lite_cache
    $ pip3 install lite-cache
    

Usage

To use in default configuration:

  • Entire cache is in 1 database file, ~/.local/litecache/cache.db

To use in custom configuration:

import lite_cache

program_cache = lite_cache.LiteCache(name='MyProgramCache', location='~/.local/litecache')
# This initializes and creates a new Sqlite3 database file in `location` directory,
# named as "`name`.cache".
# If directory does not exist, error is raised.

This strategy of having unique caches for each program is designed to navigate "same thread" or "single thread" issues with Python & Sqlite3.

  • This would not prevent issues occurring if multiple instances of the same program were launched on the same machine.
    • ie. Executing same Python script in 2 terminal tabs. This would lead to two(2) threads attempting to access one(1) Sqlite3 with same name

Development

This project uses pipenv for managing virtual-environments and Python3 dependencies for development and testing.

The standard requirements.txt is included for installation via setup.py

Tests

  • Uses unittests

Run all tests from setup.py

pipenv run python setup.py test

Run specific test

pipenv run python -m unittest tests/test_main.py

Plans

  • Interface for handling Python+Sqlite3 thread limitations.
  • Data compression options

License

GPLv3

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

lite-cache-0.1.3.tar.gz (19.4 kB view hashes)

Uploaded Source

Built Distribution

lite_cache-0.1.3-py3-none-any.whl (17.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page