numstore - fast and easy key-value storage in RAM. It only works with numbers keys and numbers values
Project description
Source code: https://github.com/anydict/numstore
Numstore - fast and easy key-value storage in RAM. It only works with numbers keys and numbers values.
This is an ideal solution if you need to store a small integer value for a huge number of integer keys.
It is high performance and low RAM consumption.
For example: if you fill the dictionary with 99999999 keys, it will take about 899 megabytes in memoryLimits on use:
- keys can only be positive integer values;
- the values must be in the range from 0 to 15 (None values cannot be used);
- all keys initially have a value of 0 (A value equal to 0 is considered a non-existent value);
- the size of the dictionary is set during initialization and cannot change during operation;
Otherwise, the dictionary has similar functionality to a regular dictionary
Usage
pip install numstore
import numstore
buffer = numstore.Dict(length=6)
buffer[100] = 1
buffer[200] = 2
buffer[300] = 3
del buffer[100]
print("get by index ", buffer[200])
print("get method ", buffer.get(300))
print("check contains ", 100 in buffer)
print("check bool ", True if buffer else False)
print("len(buffer) ", len(buffer))
print("buffer.pop(200) ", buffer.pop(200))
print("all keys ", list(buffer.keys()))
print("all values ", list(buffer.values()))
print("all items ", list(buffer.items()))
print("clear ", buffer.clear())
print("len(buffer) ", len(buffer))
buffer.save("test.pkl") # save dictionary in file
buffer.load("test.pkl") # load dictionary from file
# keys and values can be specified as a string (but these strings must contain numbers)
buffer["400"] = "4"
# # Examples of misuse
# buffer = Dict(length=3, raise_index_error=False)
# buffer["a"] = "1" # NOT WORKING (key is not number) (show UserWarning in stdout)
# buffer["1"] = "a" # NOT WORKING (value is not number) (show UserWarning in stdout)
# buffer["-1"] = 1 # NOT WORKING (negative key) (show UserWarning in stdout)
# buffer[1] = -11 # NOT WORKING (not allowed value) (show UserWarning in stdout)
# buffer[123456789] = 1 # NOT WORKING (max length=3) (show UserWarning in stdout)
Performance
One million records (1 000 000 records)
module | Speed writes | Speed random reads | Memory for one million records |
---|---|---|---|
numstore | 666988 / second | 962239 / second | 17 Mb |
numpy | 5446387 / second | 8103369 / second | 25 Mb |
dict | 6604781 / second | 2196775 / second | 100 Mb |
pysos | 86963 / second | 204624 / second | 972 Mb |
Ten million records (10 000 000 records)
module | Speed writes | Speed random reads | Memory for ten million records |
---|---|---|---|
numstore | 663046 / second | 900838 / second | 104 Mb |
numpy | 5425987 / second | 6841141 / second | 809 Mb |
dict | 5757307 / second | 1680141 / second | 8600 Mb |
pysos | 82755 / second | 206848 / second | 11700 Mb |
One hundred million records (100 000 000 records)
module | Speed writes | Speed random reads | Memory for one hundred million records |
---|---|---|---|
numstore | 643016 / second | 820369 / second | 899 Mb |
numpy | 5229830 / second | 6356026 / second | 8000 Mb |
dict | out of memory | out of memory | out of memory |
pysos | out of memory | out of memory | out of memory |
F.A.Q.
Is it thread safe?
No. It is not thread safe. In practice, synchronization mechanisms are typically desired on a higher level anyway.
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 numstore-1.2.6.tar.gz
.
File metadata
- Download URL: numstore-1.2.6.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a84a1d2dae664dabd6195e5202804e4a1e38504de146033c0cc1abd67dec4ee0 |
|
MD5 | bbed6045b7421f3943339ae6955f3cdd |
|
BLAKE2b-256 | 973eb5cd40aea0e9ea17f7e97d6b46d56bda4cdd5765ed6cfa0dea2c61ac5c06 |
File details
Details for the file numstore-1.2.6-py3-none-any.whl
.
File metadata
- Download URL: numstore-1.2.6-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38cb67b0342cee9da96a76553dcb75ba3108784ebcd844523a096bbb23872b8b |
|
MD5 | e98257f085811a97be191a13c3c668a5 |
|
BLAKE2b-256 | 8ab53982b0bc1386a7a45d2b88e7b84c3a0022cafb8ff8a6f1e0d82381b92b4f |