Skip to content

try-fail1/tshelve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tshelve

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.

About

A quicker and more efficient way to manage the shelve library by using threads.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages