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