Skip to main content

nautilus_persistence/python/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Python bindings from [PyO3](https://pyo3.rs).
17
18#![expect(
19    clippy::missing_errors_doc,
20    reason = "errors documented on underlying Rust methods"
21)]
22
23pub mod backend;
24pub mod config;
25pub mod wranglers;
26
27use nautilus_model::data::ensure_rust_extractor_registered;
28use nautilus_serialization::arrow::custom::ensure_custom_data_registered;
29use pyo3::prelude::*;
30
31/// Exposed through `nautilus_trader.persistence`.
32///
33/// # Errors
34///
35/// Returns an error if registering any module components fails.
36#[pymodule]
37pub fn persistence(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
38    ensure_custom_data_registered::<crate::test_data::RustTestCustomData>();
39    ensure_custom_data_registered::<crate::test_data::MacroYieldCurveData>();
40    ensure_custom_data_registered::<crate::test_data::RustTestParamsCustomData>();
41    ensure_custom_data_registered::<crate::test_data::RustTestPriceMapCustomData>();
42    ensure_custom_data_registered::<crate::test_data::RustTestTypedMapCustomData>();
43    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestCustomData>();
44    let _result = ensure_rust_extractor_registered::<crate::test_data::MacroYieldCurveData>();
45    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestParamsCustomData>();
46    let _result =
47        ensure_rust_extractor_registered::<crate::test_data::RustTestPriceMapCustomData>();
48    let _result =
49        ensure_rust_extractor_registered::<crate::test_data::RustTestTypedMapCustomData>();
50
51    // Test/example types (RustTestCustomData, MacroYieldCurveData) are exposed so Python tests
52    // and examples can use them; they are not gated behind cfg(test) to keep the extension build simple.
53    m.add_class::<config::PyCatalogBackend>()?;
54    m.add_class::<crate::config::StreamingConfig>()?;
55    m.add_class::<config::PyRotationConfig>()?;
56    m.add_class::<crate::config::RotationMode>()?;
57    m.add_class::<crate::test_data::RustTestFixedCustomData>()?;
58    m.add_class::<backend::writer::PyStreamingWriter>()?;
59    m.add_class::<crate::config::DataCatalogConfig>()?;
60    m.add_class::<backend::parquet::catalog::PyParquetDataCatalog>()?;
61    m.add_class::<backend::feather::PyStreamingFeatherWriter>()?;
62    m.add_class::<wranglers::bar::BarDataWrangler>()?;
63    m.add_class::<wranglers::delta::OrderBookDeltaDataWrangler>()?;
64    m.add_class::<wranglers::depth::OrderBookDepthDataWrangler>()?;
65    m.add_class::<wranglers::quote::QuoteTickDataWrangler>()?;
66    m.add_class::<wranglers::trade::TradeTickDataWrangler>()?;
67    m.add_class::<crate::test_data::RustTestCustomData>()?;
68    m.add_class::<crate::test_data::MacroYieldCurveData>()?;
69    m.add_class::<crate::test_data::RustTestParamsCustomData>()?;
70    m.add_class::<crate::test_data::RustTestPriceMapCustomData>()?;
71    m.add_class::<crate::test_data::RustTestTypedMapCustomData>()?;
72    Ok(())
73}