Skip to content

Commit ca4caa7

Browse files
committed
add documentation for examples
1 parent 48e7f4d commit ca4caa7

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--8<-- "examples/custom_dtype/README.md"
2+
3+
## Source Code
4+
5+
```python
6+
--8<-- "examples/custom_dtype/custom_dtype.py"
7+
```

examples/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Zarr Python Examples
2+
3+
This directory contains complete, runnable examples demonstrating various features and use cases of Zarr Python.
4+
5+
## Directory Structure
6+
7+
Each example is organized in its own subdirectory with the following structure:
8+
9+
```
10+
examples/
11+
├── example_name/
12+
│ ├── README.md # Documentation for the example
13+
│ └── example_name.py # Python source code
14+
└── ...
15+
```
16+
17+
## Adding New Examples
18+
19+
To add a new example:
20+
21+
1. Create a new subdirectory: `examples/my_example/`
22+
2. Add your Python code: `examples/my_example/my_example.py`
23+
3. Create documentation: `examples/my_example/README.md`
24+
4. Run the documentation generator: `python3 scripts/generate_examples_docs.py`
25+
26+
The documentation generator will automatically:
27+
- Create a documentation page at `docs/user-guide/examples/my_example.md`
28+
- Update `mkdocs.yml` to include the new example in the navigation
29+
30+
### Example README.md Format
31+
32+
Your README.md should include:
33+
34+
- A title (# Example Name)
35+
- Description of what the example demonstrates
36+
- Instructions for running the example
37+
38+
**Note:** The source code will be automatically appended to the documentation when you run the generator script.

examples/custom_dtype/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Custom Data Type Example
2+
3+
This example demonstrates how to extend Zarr Python by defining a new data type.
4+
5+
The example shows how to:
6+
7+
- Define a custom `ZDType` class for the `int2` data type from [`ml_dtypes`](https://pypi.org/project/ml-dtypes/)
8+
- Implement all required methods for serialization and deserialization
9+
- Register the custom data type with Zarr's registry
10+
- Create and use arrays with the custom data type in both Zarr v2 and v3 formats
11+
12+
## Running the Example
13+
14+
```bash
15+
python examples/custom_dtype/custom_dtype.py
16+
```
17+
18+
Or run with uv:
19+
20+
```bash
21+
uv run examples/custom_dtype/custom_dtype.py
22+
```
File renamed without changes.

0 commit comments

Comments
 (0)