Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flat file key-value store in python

Tags:

python

I'm looking for a flat-file, portable key-value store in Python. I'll be using strings for keys and either strings or lists for values. I looked at ZODB but I'd like something which is more widely used and is more actively developed. Do any of the dmb modules in Python require system libraries or a database server (like mysql or the likes) or can I write to file with any of them?

If a dbm does not support a python lists, I imagine that I can just serialize it?

like image 477
oxuser Avatar asked Sep 22 '26 04:09

oxuser


1 Answers

You may want to consider h5py which is a Python interface to HDF5.

In [1]: import h5py

In [2]: f = h5py.File('test.hdf5', 'w')

In [3]: f['abc'] = [1, 2, 3]

In [4]: f['d'] = 'hello'

In [5]: f.close()

In [6]: f2 = h5py.File('test.hdf5', 'r')

In [7]: f2['abc'].value
Out[7]: array([1, 2, 3])

In [8]: list(f2['abc'])
Out[8]: [1, 2, 3]

In [10]: f2['d'].value
Out[10]: 'hello'
like image 154
Steve Tjoa Avatar answered Sep 24 '26 23:09

Steve Tjoa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!