···11+# Python bindings for oxyroot
22+33+[](https://github.com/vvsagar/py-oxyroot/actions/workflows/CI.yml)
44+[](https://opensource.org/licenses/MIT)
55+66+> **Warning**
77+> This project is an early prototype and is not yet recommended for production use. For a mature and well-tested alternative, please consider using [uproot](https://github.com/scikit-hep/uproot5).
88+99+A fast, Rust-powered Python reader for CERN ROOT files.
1010+1111+This package provides a simple and Pythonic interface bindings to `oxyroot`, a rust package, to read data from `.root` files, inspired by libraries like `uproot`. It leverages the speed of Rust for high-performance data extraction and integrates with the scientific Python ecosystem by providing data as NumPy arrays.
1212+1313+## Features
1414+1515+- **High-Performance**: Core logic is written in Rust for maximum speed.
1616+- **Parquet Conversion**: Convert TTrees directly to Apache Parquet files with a single command.
1717+- **NumPy Integration**: Get branch data directly as NumPy arrays.
1818+- **Simple, Pythonic API**: Easy to learn and use, and similar to `uproot`
1919+2020+## Quick Start
2121+2222+Here's how to open a ROOT file, access a TTree, and read a TBranch into a NumPy array.
2323+2424+```python
2525+import oxyroot
2626+import numpy as np
2727+2828+# Open the ROOT file
2929+file = oxyroot.open("ntuples.root")
3030+3131+# Get a TTree
3232+tree = file["mu_mc"]
3333+3434+# List branches in the tree
3535+print(f"Branches: {tree.branches()}")
3636+3737+# Get a specific branch and its data as a NumPy array
3838+branch = tree["mu_pt"]
3939+data = branch.array()
4040+4141+print(f"Read branch '{branch.name}' into a {type(data)}")
4242+print(f"Mean value: {np.nanmean(data):.2f}")
4343+```
4444+4545+## Converting to Parquet
4646+4747+You can easily convert all (or a subset of) branches in a TTree to a Parquet file.
4848+4949+```python
5050+# Convert the entire tree to a Parquet file
5151+tree.to_parquet("output.parquet")
5252+5353+# Convert specific columns to a Parquet file with ZSTD compression
5454+tree.to_parquet(
5555+ "output_subset.parquet",
5656+ columns=["mu_pt", "mu_eta"],
5757+ compression="zstd"
5858+)
5959+```
6060+6161+## Performance
6262+6363+`oxyroot` is designed to be fast. Here is a simple benchmark comparing the time taken to read all branches of a TTree with `uproot` and `oxyroot`.
6464+6565+```python
6666+import oxyroot
6767+import uproot
6868+import time
6969+7070+file_name = "ntuples.root"
7171+tree_name = 'mu_mc'
7272+7373+# Time uproot
7474+start_time = time.time()
7575+up_tree = uproot.open(file_name)[tree_name]
7676+for branch in up_tree:
7777+ if branch.typename != "std::string":
7878+ branch.array(library="np")
7979+end_time = time.time()
8080+print(f"Uproot took: {end_time - start_time:.3f}s")
8181+8282+# Time oxyroot
8383+start_time = time.time()
8484+oxy_tree = oxyroot.open(file_name)[tree_name]
8585+for branch in oxy_tree:
8686+ branch.array()
8787+end_time = time.time()
8888+print(f"Oxyroot took: {end_time - start_time:.3f}s")
8989+```
9090+9191+## License
9292+9393+This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
9494+9595+## Contributing
9696+9797+Contributions are welcome! Please feel free to submit a pull request or open an issue.