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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tshelve-1.0.0.tar.gz
.
File metadata
- Download URL: tshelve-1.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | addeaa7359961c07d1e1cf95cb1a8c1aecfaa31909b6bda4f129d1568b947286 |
|
MD5 | d3178612c73741cffb858ed18f580dd6 |
|
BLAKE2b-256 | 5bf1c0737ba6aaff82749e4e7a93b8154aa1675a860b46db86930a022b00f0ba |
File details
Details for the file tshelve-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: tshelve-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f334806345395608d494f4289245348f221a77d298e783e80add16c837fb24a |
|
MD5 | 2625ed735f5e8e3ac699f0320967bab9 |
|
BLAKE2b-256 | 5b13442367624f91ce0ecee944876bffa7d8a33d147655a9e5c728502d84744f |