Skip to main content

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 999999999 keys, it will take about 899 megabytes in memory

Limits 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numstore-1.2.5.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

numstore-1.2.5-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file numstore-1.2.5.tar.gz.

File metadata

  • Download URL: numstore-1.2.5.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

Hashes for numstore-1.2.5.tar.gz
Algorithm Hash digest
SHA256 932077e39263a17612c18a9ad2251ed89cb378b954efb5d461e133b181ce512c
MD5 42e23c502ad7ff3388984d2cf033756a
BLAKE2b-256 20aab5537237c25ca53c2bed8a23161923cb28187dc38e919e6b8f25e26ce08f

See more details on using hashes here.

File details

Details for the file numstore-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: numstore-1.2.5-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

Hashes for numstore-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1d2eff045585fcdb1bb4faabaacf648b5b02384fcffb36533d2f04a01b8322a1
MD5 ffb814bb7ecf2ec26ad5c9eabb47ad55
BLAKE2b-256 067b5b3d05d242afc0ddc6b799b490e2b8b741ab96e9b7a054544c01e6df2090

See more details on using hashes here.

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