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    ensure_custom_data_registered::<crate::test_data::RustTestPriceMapCustomData>();
43    ensure_custom_data_registered::<crate::test_data::RustTestTypedMapCustomData>();
44    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestCustomData>();
45    let _result = ensure_rust_extractor_registered::<crate::test_data::MacroYieldCurveData>();
46    let _result = ensure_rust_extractor_registered::<crate::test_data::RustTestParamsCustomData>();
47    let _result =
48        ensure_rust_extractor_registered::<crate::test_data::RustTestPriceMapCustomData>();
49    let _result =
50        ensure_rust_extractor_registered::<crate::test_data::RustTestTypedMapCustomData>();
51
52    // Test/example types (RustTestCustomData, MacroYieldCurveData) are exposed so Python tests
53    // and examples can use them; they are not gated behind cfg(test) to keep the extension build simple.
54    m.add_class::<crate::backend::session::DataBackendSession>()?;
55    m.add_class::<crate::backend::session::DataQueryResult>()?;
56    m.add_class::<backend::session::NautilusDataType>()?;
57    m.add_class::<catalog::PyParquetDataCatalog>()?;
58    m.add_class::<feather::PyStreamingFeatherWriter>()?;
59    m.add_class::<wranglers::bar::BarDataWrangler>()?;
60    m.add_class::<wranglers::delta::OrderBookDeltaDataWrangler>()?;
61    m.add_class::<wranglers::depth::OrderBookDepth10DataWrangler>()?;
62    m.add_class::<wranglers::quote::QuoteTickDataWrangler>()?;
63    m.add_class::<wranglers::trade::TradeTickDataWrangler>()?;
64    m.add_class::<crate::test_data::RustTestCustomData>()?;
65    m.add_class::<crate::test_data::MacroYieldCurveData>()?;
66    m.add_class::<crate::test_data::RustTestParamsCustomData>()?;
67    m.add_class::<crate::test_data::RustTestPriceMapCustomData>()?;
68    m.add_class::<crate::test_data::RustTestTypedMapCustomData>()?;
69    Ok(())
70}