Skip to content

Conversation

tlambert03
Copy link

@tlambert03 tlambert03 commented Sep 13, 2025

proof of principle to make the zarr dependency optional. (plenty of space to discuss the exact code patterns, and how the hatch matrix was done)

@dstansby
Copy link
Collaborator

dstansby commented Sep 15, 2025

Thanks for this, and the PR over at ome-zarr models! I'm very pro having an optional dependency on zarr-python in both places, if it's possible.

My immediate question is how are you envisaging using this library without zarr-python, with both to_zarr() and from_zarr() not working? All my personal use cases need one or other of those methods, but it's very possible I'm missing a way to use these libraries!

@d-v-b
Copy link
Collaborator

d-v-b commented Sep 15, 2025

pydantic-zarr essentially defines a bidirectional mapping from zarr hierarchies to JSON documents, and zarr-python is just one of several possible ways to handle the translation.

eventually, an API like this would be great:

# use zarr python
GroupSpec.to_zarr(engine='zarr-python')
# use tensorstore
GroupSpec.to_zarr(engine='tensorstore')
# use a custom zarr engine
GroupSpec.to_zarr(engine=MyCustomZarrEngine)

But the return type of to_zarr starts to get complicated here!

@tlambert03
Copy link
Author

how are you envisaging using this library without zarr-python, with both to_zarr() and from_zarr() not working

yeah, the mapping to/from json documents that @d-v-b mentioned is what I’m after. And the use case is https://github.com/pymmcore-plus/ome-writers … which is a library for writing both ome-tiff and ome-zarr as data comes off the microscope. We have alternative backends: for zarr it’s either tensorstore or acquire-zarr (high performance libs that are both much faster than zarr-python).

Having a model that simplifies the process of constructing valid, spec-conforming json documents, without stipulating exactly how those documents will be written to disk, is what I’m after.

@dstansby
Copy link
Collaborator

So the idea is you would manually create one of the models, and then serialise it to JSON using the methods available through pydantic (.model_dump_json()) and 'manually' write it to the correct Zarr metadata file? That sounds good to me - just want to make sure, partly so the workflow in this case can be documented.

@tlambert03
Copy link
Author

tlambert03 commented Sep 15, 2025

Yes exactly.👍

Edit: for what it’s worth, if this ome-models-zarr were no more than pydantic, I would also likely use it as a public object for declaring intention prior to creating a stream: I.e “I want to acquire a well plate with these wells, etc”

Comment on lines +44 to +48
- name: Run Tests (without zarr)
if: matrix.zarr-version == 'none'
run: |
hatch run test-base.py${{ matrix.python-version }}:list-env
hatch run test-base.py${{ matrix.python-version }}:test-cov
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-v-b, let me know if you have a better idea for doing the hatch matrix here... or if you're happy to switch this repo over to using uv and do it similarly to ome-zarr-models/ome-zarr-models-py#280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants