$ show unit8co/darts
Darts is a Python library for time series forecasting and anomaly detection. It provides a unified API for a wide range of models, from classical statistical methods (ARIMA, Exponential Smoothing) to deep learning architectures (N-BEATS, TFT, TiDE, Transformer) and foundation models (Chronos, TimesFM, PatchTST-FM). The library also includes data preprocessing transformers (scaling, missing value filling, Box-Cox, DTW), anomaly detection scorers and detectors, explainability tools (SHAP, TFT attention), and comprehensive evaluation metrics. The architecture is modular: core TimeSeries data structure, model registry with lazy imports, transformer pipeline, and safe serialization. External dependencies include pandas, numpy, scikit-learn, PyTorch, PyTorch Lightning, and many optional packages for specific models. The codebase is well-tested with extensive unit and integration tests, and follows good engineering practices with CI/CD, dependency audits, and semantic versioning.
The LLM identified 4 files worth highlighting for reuse:
Abstract base class for all data transformers. Provides static methods ts_transform, ts_fit, ts_inverse_transform that operate on individual TimeSeries. Implements component masking (apply/unapply_component_mask) for selective transformation of components, stack_samples/unstack_samples for vectorized pointwise operations, and parallelization via _parallel_apply. This pattern is reusable for any series-to-series transformation and can be extracted with minimal changes.
Implements RestrictedUnpickler with an allowlist/blocklist mechanism to prevent arbitrary code execution during model loading. Provides is_allowed_global, restricted_pickle_load, and context managers (safe_globals, add_safe_globals) for toggling allowed globals. This is a reusable security pattern for any Python project that needs to deserialize untrusted data.
Chains multiple data transformers into a single Pipeline object. Automatically handles fit/transform/inverse_transform traversal, skipping non-fittable steps, and supports partial inverse transformation. The pattern is generic and can be reused for any sequence of transformations that follow the fit/transform/inverse API.
Provides setup_lazy_imports function to defer importing heavy third-party modules (torch, sklearn, etc.) until they are actually used. This improves startup time and allows graceful degradation when optional dependencies are missing. The pattern is reusable in any Python library with optional dependencies.