h5ify
Save Python dictionaries into HDF5 files; load HDF5 files into Python dictionaries.
The dictionary can be a nested dictionary of dictionaries, the terminal values of which are numbers, lists/tuples of numbers, arrays, etc. If the value of a key is not another dictionary, it is stored as a Dataset in the HDF5 file, otherwise it creates a new Group.
The attrs key can be used at each level of a nested dictionary to store metadata for the corresponding Group objects in .attrs. This currently cannot be used to store .attrs metadata for Dataset objects. The value for each attrs key must be a dictionary that is not nested.
Install
pip install h5ify
Examples
Make a small dictionary, then save it.
import h5ify
d = {'x': 1.0, 'y': 2, 'z': [1, 2, 3], 'attrs': {'info': 'README example'}}
h5ify.save('tmp.h5', d)
Load the saved dictionary.
dd = h5ify.load('tmp.h5')
print(dd)
{'attrs': {'info': 'README example'}, 'x': 1.0, 'y': 2, 'z': array([1, 2, 3])}
Note that lists/tuple are converted to numpy arrays by h5py.
You can use the usual h5py API to open the stored HDF5 file.
import h5py
with h5py.File('tmp.h5', 'r') as f:
for key, val in f.items():
print(key, val[()])
for key, val in f.attrs.items():
print(key, val)
x 1.0
y 2
z [1 2 3]
info README example
h5ify opens HDF5 files in a mode, meaning "Read/write if exists, create otherwise". You cannot save a dictionary with the same file name and Dataset keys.
h5ify.save('tmp.h5', d)
ValueError: Unable to synchronously create dataset (name already exists)
You can append values that are not yet saved to the same file, however.
h5ify.save('tmp.h5', {'w': 42})
print(h5ify.load('tmp.h5'))
{'attrs': {'info': 'README example'}, 'w': 42, 'x': 1.0, 'y': 2, 'z': array([1, 2, 3])}
Or you can overwrite by specifying the write mode:
h5ify.save('tmp.h5', {**d, 'w': 42}, mode = 'r')
print(h5ify.load('tmp.h5'))
{'attrs': {'info': 'README example'}, 'w': 42, 'x': 1.0, 'y': 2, 'z': array([1, 2, 3])}
Any additional keyword arguments to h5ify.save are passed to the create_dataset function in h5py.
h5ify.save('tmp.h5', {'comp': [100]}, compression = 'gzip', compression_opts = 9)
That should cover it. Let me know if you have questions!
Metadata
Release files for h5ify 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| h5ify-0.2.3.tar.gz | 3.3 kB | Without provenance | Details for h5ify-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| h5ify-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for h5ify-0.2.3-py3-none-any.whl |
Total release size: 6.9 kB
Release files / h5ify-0.2.3.tar.gz
| Download URL | h5ify-0.2.3.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d19e4172b59b7cc58e27224e27fc42a650624b3ab9652be9d6e9eea448bba09
|
|
BLAKE2b-256 checksum How to use checksums |
bde4e8ccbfa7f2daa77502bec1bfd8b5ccd08cc51630de07046e847a05aafd2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.15
|
Release files / h5ify-0.2.3-py3-none-any.whl
| Download URL | h5ify-0.2.3-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4b2cb23c53c72f9d77b2ceef1672075cd378b6f5bb1359eda06630e4a38f07b
|
|
BLAKE2b-256 checksum How to use checksums |
0967d91988f65e65442850908e46d287a2240142d2e4aa7c29d888708f5f7578
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.15
|
Security for h5ify 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.