Skip to main content

A faster kind of Python shelf

Project description

Description

A near dupicate of the shelve module, but with threading used under the hood to speed up execution time.

Purpose

Regular shelve operations can be notoriously slow. The tshelve module aims to provide a more efficient program, that is still similar to the built-in.

Installation

Installing tshelve should be done with PIP:

$ pip install tshelve

Benefits

  • A more meaningful repr:

    The default repr:

    repr(shelve.Shelf({}) == '<shelve.Shelf object at 0x00572CB8>'

    tshelve’s repr:

    repr(tshelve.TShelf({})) == TShelf(dict={}, protocol=5, writeback=False, keyencoding='utf-8')
  • Similar to the shelve module in the standard library.

The amount of speed up that tshelve brings will depend on the code. However, there will usually be a speed-up, especially in code that interacts heavily with the module.

The following block of code was run with shelve.open and tshelve.open. Both tshelve and shelve were tested in the same environment to ensure realistic results.

import shelve
import tshelve

sync_open = shelve.open('shell', writeback=True)
thread_open = tshelve.open('shell', writeback=True)

def speedup(opened):
    opened['testvalue'] = False
    opened['tester'] = 5324
    opened['tester']
    opened.get('testvalue')
    opened['testit'] = 'Hello'
    opened.items()
    opened.keys()
    opened.values()
    del opened['testit']
    'testvalue' in opened
    for _ in opened:
        pass
    opened.popitem()
    opened.sync()
    opened.close()

speedup(sync_open)
speedup(thread_open)

The difference in execution time between the two is drastic. tshelve operations were, on average, nearly 44% faster than those found in the shelve module.

Example

import tshelve

with tshelve.open('shell') as f:
    f['fruit'] = ['apple', 'banana']
    f['language'] = 'Python'
    del f['fruit']
    print(f['language'])

License

This module is currently licensed under the MIT license.

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

tshelve-1.0.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

tshelve-1.0.0-py3-none-any.whl (3.1 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