Skip to main content

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.

Release files for tshelve 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tshelve 1.0.0
File Size Uploaded
tshelve-1.0.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tshelve 1.0.0
File Interpreter ABI Platform
tshelve-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.7 kB

Release files / tshelve-1.0.0.tar.gz

Download URL tshelve-1.0.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
addeaa7359961c07d1e1cf95cb1a8c1aecfaa31909b6bda4f129d1568b947286
BLAKE2b-256 checksum
How to use checksums
5bf1c0737ba6aaff82749e4e7a93b8154aa1675a860b46db86930a022b00f0ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release files / tshelve-1.0.0-py3-none-any.whl

Download URL tshelve-1.0.0-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f334806345395608d494f4289245348f221a77d298e783e80add16c837fb24a
BLAKE2b-256 checksum
How to use checksums
5b13442367624f91ce0ecee944876bffa7d8a33d147655a9e5c728502d84744f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page