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 catalog;
25pub mod config;
26pub mod feather;
27pub mod wranglers;
28
29use nautilus_model::data::ensure_rust_extractor_registered;
30use nautilus_serialization::arrow::custom::ensure_custom_data_registered;
31use pyo3::prelude::*;
32
33/// Exposed through `nautilus_trader.persistence`.
34///
35/// # Errors
36///
37/// Returns a `PyErr` if registering any module components fails.
38#[pymodule]
39pub fn persistence(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
40    ensure_custom_data_registered::<crate::test_data::RustTestCustomData>();
41    ensure_custom_data_registered::<crate::test_data::MacroYieldCurveData>();
42    ensure_custom_data_registered::<crate::test_data::RustTestParamsCustomData>();
43    ensure_custom_data_registered::<crate::test_data::RustTestPriceMapCustomData>();
44    ensure_custom_data_registered::<crate::test_data::RustTestTypedMapCustomData>();
45    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestCustomData>();
46    let _result = ensure_rust_extractor_registered::<crate::test_data::MacroYieldCurveData>();
47    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestParamsCustomData>();
48    let _result =
49        ensure_rust_extractor_registered::<crate::test_data::RustTestPriceMapCustomData>();
50    let _result =
51        ensure_rust_extractor_registered::<crate::test_data::RustTestTypedMapCustomData>();
52
53    // Test/example types (RustTestCustomData, MacroYieldCurveData) are exposed so Python tests
54    // and examples can use them; they are not gated behind cfg(test) to keep the extension build simple.
55    m.add_class::<crate::backend::session::DataBackendSession>()?;
56    m.add_class::<crate::backend::session::DataQueryResult>()?;
57    m.add_class::<config::PyCatalogBackend>()?;
58    m.add_class::<crate::config::StreamingConfig>()?;
59    m.add_class::<config::PyRotationConfig>()?;
60    m.add_class::<crate::test_data::RustTestFixedCustomData>()?;
61    m.add_class::<backend::writer::PyStreamingWriter>()?;
62    m.add_class::<crate::config::DataCatalogConfig>()?;
63    m.add_class::<catalog::PyParquetDataCatalog>()?;
64    m.add_class::<feather::PyStreamingFeatherWriter>()?;
65    m.add_class::<wranglers::bar::BarDataWrangler>()?;
66    m.add_class::<wranglers::delta::OrderBookDeltaDataWrangler>()?;
67    m.add_class::<wranglers::depth::OrderBookDepthDataWrangler>()?;
68    m.add_class::<wranglers::quote::QuoteTickDataWrangler>()?;
69    m.add_class::<wranglers::trade::TradeTickDataWrangler>()?;
70    m.add_class::<crate::test_data::RustTestCustomData>()?;
71    m.add_class::<crate::test_data::MacroYieldCurveData>()?;
72    m.add_class::<crate::test_data::RustTestParamsCustomData>()?;
73    m.add_class::<crate::test_data::RustTestPriceMapCustomData>()?;
74    m.add_class::<crate::test_data::RustTestTypedMapCustomData>()?;
75    Ok(())
76}