# Is there a Julia function that returns h5 group structures à la h5dump?

**URL:** <https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778>\
**Category:** Data\
**Tags:** hdf5\
**Created:** [August 13, 2023, 11:37pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778 "2023-08-13T23:37:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [August 13, 2023, 11:37pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/1 "2023-08-13T23:37:08Z")

</div>

I’m looking for a function that maps h5 data structures, i.e. variable paths, names and Types, and attribute paths, names and Types. This would be similar to [h5dump](https://docs.hdfgroup.org/hdf5/develop/_view_tools_view.html).

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 14, 2023, 1:58am UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/2 "2023-08-14T01:58:13Z")

</div>

See [HDF5.jl](https://juliaio.github.io/HDF5.jl/stable/).

---

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [August 14, 2023, 4:07am UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/3 "2023-08-14T04:07:07Z")

</div>

I’ve looked through the documentation, it’s a fantastic library. But I don’t see any support for `h5dump` like functionality. The closest would be what’s displayed by `show`. There doesn’t seem to be anything that returns the full data tree path + attribute names. I could do this with HDF5.jl and number of nested loops and if statements but was wondering if this had already been done as I see this kind of functionality very useful.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [August 14, 2023, 4:35am UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/4 "2023-08-14T04:35:24Z")

</div>

Based on some old discussion threads about HDF5.jl, I believe the default in-REPL file display should show most of the information you’re looking for: [Using HDF5.jl and reading h5 data to Julia? - #7 by stephancb](https://discourse.julialang.org/t/using-hdf5-jl-and-reading-h5-data-to-julia/93232/7)

---

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [August 14, 2023, 5:08am UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/5 "2023-08-14T05:08:19Z")

</div>

I think most of what i need is displayed by `show` but I guess there’s no function that returns a `Dict` or `NamedTuple` with that information and possibly options to return additional information like `Types`?

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [August 14, 2023, 2:58pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/6 "2023-08-14T14:58:28Z")

</div>

Oh, I was under the impression you just wanted printed output since that’s all `h5dump` does. I also didn’t find any functionality for obtaining an in-memory representation of overall file structure. It might be worth asking on GitHub or Slack about whether there’s some external library for this (or if it should be added as a feature request).

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 14, 2023, 5:32pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/7 "2023-08-14T17:32:02Z")

</div>

> [@alex-s-gardner](#):
>
> But I don’t see any support for `h5dump` like functionality. The closest would be what’s displayed by `show`. There doesn’t seem to be anything that returns the full data tree path + attribute names.

All of the information is there, you just need to loop over the contents. e.g.

```julia
f = h5open("test.h5", "r")

```

returns an object `f` that acts like a dictionary of `names => datasets/groups`, which you can iterate over like any other dictionary-like iterator (e.g. use `keys(f)` to get a list of names). If there is a dataset `"array"`, then you can query its size with `size(f["array"])` and its element type with `eltype(f["array"])`. You can loop over its attributes with `attributes(f["array"])`, and so forth.

Your original post asked for a function that returns data "structures "— this is what HDF5.jl provides. If you want h5dump-like pretty printing, you could add that on top of this. But HDF5.jl is more focused on making the information availalble programmatically, not as text. (If you just want text, why not use `h5dump`?)

---

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [August 14, 2023, 5:55pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/8 "2023-08-14T17:55:03Z")

</div>

So I’m looking for an in-memory dump of the full structure so that I can easily query the full h5 as oppose to needing to write a more complex loop structure to retrieve everything. I’m working with files that have vary complex structures with multiple subgroup levels.

My goal is to write a high level function that loads a subset an h5 file into memory with a structure that mimics the original h5. The user would supply variable and attribute names with optional dimension bounds. For my specific specific application I was going to build a datatree of the file format so I could then construct a structure to place the data into. But maybe I’m going about this wrong.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 14, 2023, 6:06pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/9 "2023-08-14T18:06:23Z")

</div>

> [@alex-s-gardner](#):
>
> For my specific specific application I was going to build a datatree of the file format so I could then construct a structure to place the data into

`f = h5open(...)` already acts like a data tree. Why do you care how it is stored internally?

> [@alex-s-gardner](#):
>
> so that I can easily query the full h5 as oppose to needing to write a more complex loop structure to retrieve everything

What kind of data structure do you want? A dictionary of dictionaries, for example, will be accessed much like the `f` object you get from `h5open`.

---

<div class="post-metadata">

**Author:** ![alex-s-gardner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alex-s-gardner/32/30210_2.png) [@alex-s-gardner](https://discourse.julialang.org/u/alex-s-gardner)\
**Post date:** [August 14, 2023, 6:17pm UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/10 "2023-08-14T18:17:03Z")

</div>

Thanks @stevengj, I think I was just approaching the problem the wrong way. Let me take a step back and reassess how I can get HDF5 to do what I want. Thanks for all the guidance.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [September 6, 2023, 8:18am UTC](https://discourse.julialang.org/t/is-there-a-julia-function-that-returns-h5-group-structures-a-la-h5dump/102778/11 "2023-09-06T08:18:21Z")

</div>

I’m guessing this issue is related:

> <https://github.com/JuliaIO/HDF5.jl/issues/1096#issue-1850329551>
>
> Is there a path to HDF5.jl supporting tab completion? It would be very powerful …for navigating opened h5 files but I'm guessing there is a good reason that it doesn't already exist.

which subsequently led to another forum thread:

> [@How does nested tab completion work in the REPL?](https://discourse.julialang.org/t/how-does-nested-tab-completion-work-in-the-repl/102953/4):
>
> Setup: begin using HDF5, Downloads url = "https://github.com/evetion/SpaceLiDAR-artifacts/releases/download/v0.3.0/ATL08\_20201121151145\_08920913\_006\_01.h5"; fn = Downloads.download(url, basename(url)) h5f = h5open(fn) end begin h5\_to\_tuple(h5o::Union{HDF5.File,HDF5.Group}) = NamedTuple(Symbol.(keys(h5o)) .=\> h5\_to\_tuple.(getindex.((h5o,), keys(h5o)))) h5\_to\_tuple(h5o) = h5o nt = h5\_to\_tuple(h5f) end This works in the REPL: julia\> nt.[TAB] METADATA …
