You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

strstrdict

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strstrdict

lower memory alternative to string-to-string dict

0.0.2
PyPI
Maintainers
1
logo

PyPI - License Tests

strstrdict

Low memory overhead alternative to Python's dict, with string keys and values.

Uses half of the memory of dict for strings of length 40, at the cost of being half as fast. More improvement at shorter strings, less at longer ones. See more at benchmarks.

📝 Documentation

Drop-in replacement for dict with the following limitations:

  • Only supports string keys and values.
  • Iterating order is unspecified.
  • Any modification invalidates iterators.
>>> from strstrdict import StrStrDict

>>> d = StrStrDict()
>>> d['foo'] = 'bar'
>>> d['foo']
'bar'

To KISS, this project only supports a string to string dictionary.

More:

🐍 Installation

pip install strstrdict

📈 Benchmarks

Filling a dictionary with 1m items, key and value strings 5-10 chars long, from a pool of 2m random strings. Then reading values 1m times, with a 50% hit rate.

Fill time (s)Read time (s)Memory (MB)
dict0.19s0.17s159.60
sqlitedict110.31s51.79s69.41
strstrdict0.41s0.44s64.44

Filling a dictionary with 1m items, key and value strings 20-30 chars long, from a pool of 2m random strings. Then reading values 1m times, with a 50% hit rate.

Fill time (s)Read time (s)Memory (MB)
dict0.26s0.21s193.23
sqlitedict19.17s41.09s139.40
strstrdict0.41s0.42s95.38

Filling a dictionary with 1m items, key and value strings 100-200 chars long, from a pool of 2m random strings. Then reading values 1m times, with a 50% hit rate.

Fill time (s)Read time (s)Memory (MB)
dict0.38s0.24s447.02
sqlitedict111.31s42.62s572.88
strstrdict0.76s0.56s344.73

🙏 Thanks & Credits

parallel-hashmap for their amazing header-only library!

pysimdjson for a reference how to write a cython lib!

Footnotes

  • SqliteDict is used with commiting every 1000 writes. Note that SqliteDict is not intended for in-memory storage, but still has great efficiency at short strings. 2 3

Keywords

dict

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts