This file provides guidance to Claude Code (claude.ai/code) when working with the Python module.
The Python module depends on the C++ shared library (libtsfile). Build C++ first:
# From repo root
./mvnw clean package -P with-cpp -DskipTests# Build everything via Maven (builds C++ then Python)
./mvnw clean verify -P with-python
# Or build directly (after C++ is built)
cd python
python setup.py build_ext --inplace
# Run tests
pytest tests/
# Run a single test
pytest tests/test_write_and_read.py -k "test_name"
# ASan/LSan coverage of the bindings (Linux; run from the repo root; see
# SANITIZER.md). TSFILE_SANITIZER is required or test_sanitizer_ownership.py
# skips every case, and the runtime must be preloaded or the instrumented
# extensions abort on import.
./mvnw -P with-python -Dtsfile.sanitizer=address -Dbuild.type=RelWithDebInfo \
-Dbuild.test=OFF clean test-compile
TSFILE_SANITIZER=address \
ASAN_OPTIONS="detect_leaks=0:abort_on_error=1:halt_on_error=1" \
LSAN_OPTIONS="suppressions=$PWD/python/tests/sanitizer/lsan_suppressions.txt" \
LD_PRELOAD="$(gcc -print-file-name=libasan.so):$(gcc -print-file-name=libstdc++.so.6)" \
python/venv/bin/python -m pytest python/tests/test_sanitizer_ownership.py -v
# Format code
cd ../ && ./mvnw spotless:apply # Uses Black 26.3.1python/tsfile/
├── __init__.py # Public API exports
├── constants.py # Enums: TSDataType, TSEncoding, Compressor, ColumnCategory
├── schema.py # TimeseriesSchema, DeviceSchema, TableSchema, ColumnSchema
├── tablet.py # Tablet class for batch columnar data
├── field.py / row_record.py # Row-based data structures
├── tag_filter.py # Tag filtering DSL for queries
├── tsfile_table_writer.py # High-level table writer API
├── utils.py # to_dataframe(), dataframe_to_tsfile()
├── exceptions.py # Custom exception types
│
├── tsfile_py_cpp.pyx # Cython core: Python ↔ C++ type conversion
├── tsfile_reader.pyx # Cython reader wrapper
├── tsfile_writer.pyx # Cython writer wrapper
├── tsfile_cpp.pxd # C++ interface declarations (cwrapper)
│
└── dataset/ # High-level multi-file API
├── dataframe.py # TsFileDataFrame (pandas-like interface)
├── timeseries.py # Timeseries, AlignedTimeseries
├── reader.py # Multi-file reader coordination
└── merge.py # K-way merge for overlapping time ranges
- Layered design: C++ core → Cython bridge (
*.pyx) → Pure Python API setup.pycopies pre-built C++ headers and shared libraries from../cpp/target/build/- Cython binds to
cwrapper/tsfile_cwrapper.hfrom the C++ module - C error codes are mapped to Python exceptions via
check_error()intsfile_py_cpp.pyx - Requires Python 3.9+, numpy >= 2.0, pandas >= 2.0, pyarrow >= 16.0
- Formatter: Black 26.3.1 (via Spotless Maven plugin)
- Framework: pytest
- Tests in
python/tests/, 19 test files covering write, read, filtering, DataFrame conversion, and Arrow format
Every new file must include the Apache License 2.0 header at the top. For Python files, use # line comments. For .pyx/.pxd files, also use # comments. See any existing file for the exact wording.
- Do NOT add
Co-Authored-Bytrailer to commit messages.