h5py_like
Some base classes and helper functions for an approximately h5py-like API in python 3.7+.
Use case
You have a library which reads/writes contiguous regions of chunked numeric arrays, and want to make it behave somewhat like h5py.
Not supported
- Empty and scalar data spaces
- Logical indexing
- Broadcasting (other than scalar)
- Dimension scales
Differences from h5py
- Access modes are converted to enums, although they are largely compatible with the
strforms"x"is preferred over"w-"for exclusive creation
Usage
See the trivial HDF5 implementation in the tests package.
Create your own Dataset, Group, File, and AttributeManager classes,
implementing their abstract methods.
Because Files should subclass your Group, the base class here is a mixin.
It should come before the Group in the MRO.
Methods containing write operations should be given the @mutation decorator.
This checks their mode attribute and raises an error if it is readonly.
from h5py_like import DatasetBase, GroupBase, AttributeManagerBase, FileMixin, mutation
class MyDataset(DatasetBase):
# ... implement abstract methods
@mutation
def __setitem__(self, idx, val):
...
class MyGroup(GroupBase):
# ... implement abstract methods
pass
class MyFile(FileMixin, MyGroup):
# ... implement abstract methods
pass
class MyAttributeManager(AttributeManagerBase):
# ... implement abstract methods
pass
Helpers
h5py_like.shape_utils contains a variety of helper functions,
to simulate numpy's flexibility.
Testing
A suite of tests for basic h5py-like functionality is included.
To use it, you must be using pytest, and define a fixture which yields an instance of your File implementation.
Then you just need to subclass the provided abstract test classes:
conftest.py
import pytest
@pytest.fixture
def file_():
yield MyFile("my_name")
test_implementation.py
from h5py_like.test_utils import FileTestBase, GroupTestBase, DatasetTestBase, ModeTestBase
# concrete class names must start with Test
class TestFile(FileTestBase):
pass
class TestGroup(GroupTestBase):
pass
class TestDataset(DatasetTestBase):
pass
class TestMode(ModeTestBase):
def factory(self, mode):
# Instantiate your File object in the given mode in a way which is repeatable within a method.
return MyFile(mode)
If your dataset implementation supports chunking and threading, use the ThreadedDatasetTestBase base class instead.
The provided base classes test some of the expected functionality, even if you don't write any methods in your test classes. You can add more tests if you like, or override those you want to change, or decorate any you to skip or xfail.
The GroupTestBase provides a group_name attribute and a self.group(parent) method for creating a group of that name.
The DatasetTestBase provides dataset_ name, shape, and dtype, and a self.dataset(parent) method for making that dataset.
Notes
If you only want to implement part of the h5py-like API, just raise NotImplementedError().
Then your classes are being explicit about what they do and don't support.
Metadata
Release files for h5py-like 0.6.0
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 | |
|---|---|---|---|---|
| h5py_like-0.6.0.tar.gz | 19.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| h5py_like-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.1 kB
Release files / h5py_like-0.6.0.tar.gz
| Download URL | h5py_like-0.6.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd4b998c260e68c0183380b54e609bc3ab2b22f036ff1fd3006be07f40654550
|
|
BLAKE2b-256 checksum How to use checksums |
e9a3f4a20799ed55f88f6a54442a1854207bfbc978d6d095d9c4b2fe9177f320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
|
Release files / h5py_like-0.6.0-py3-none-any.whl
| Download URL | h5py_like-0.6.0-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf92e575c15041b731d5694217aae10790995ed7215f1216b50ef93e4d934a16
|
|
BLAKE2b-256 checksum How to use checksums |
e4448b82f01929fb949b91cafe916d1cd583e51ec0fe96d91a6506cd012f274b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
|
Security for h5py-like 0.6.0
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.