Skip to main content

nautilus_common/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 actor;
24pub mod cache;
25pub mod clock;
26pub mod custom;
27pub mod enums;
28pub mod fifo;
29pub mod greeks;
30pub mod listener;
31pub mod logging;
32pub mod msgbus;
33pub mod runtime;
34pub mod signal;
35pub mod timer;
36pub mod xrate;
37
38use pyo3::prelude::*;
39
40/// Loaded as `nautilus_pyo3.common`.
41///
42/// # Errors
43///
44/// Returns a `PyErr` if registering any module components fails.
45#[rustfmt::skip]
46#[pymodule]
47pub fn common(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
48    m.add_class::<crate::custom::CustomData>()?;
49    m.add_class::<crate::signal::Signal>()?;
50    m.add_class::<crate::timer::TimeEvent>()?;
51    m.add_class::<crate::cache::CacheConfig>()?;
52    m.add_class::<crate::python::actor::PyDataActor>()?;
53    m.add_class::<crate::python::cache::PyCache>()?;
54    m.add_class::<crate::python::fifo::PyFifoCache>()?;
55    m.add_class::<crate::python::clock::PyClock>()?;
56    m.add_class::<crate::python::greeks::PyGreeksCalculator>()?;
57    m.add_class::<crate::python::logging::PyLogger>()?;
58    m.add_class::<crate::actor::data_actor::DataActorConfig>()?;
59    m.add_class::<crate::actor::data_actor::ImportableActorConfig>()?;
60    m.add_class::<crate::msgbus::BusMessage>()?;
61    m.add_class::<crate::msgbus::database::DatabaseConfig>()?;
62    m.add_class::<crate::msgbus::database::MessageBusConfig>()?;
63    m.add_class::<crate::python::msgbus::PyMessageBus>()?;
64    m.add_class::<crate::enums::ComponentState>()?;
65    m.add_class::<crate::enums::ComponentTrigger>()?;
66    m.add_class::<crate::enums::Environment>()?;
67    m.add_class::<crate::enums::LogColor>()?;
68    m.add_class::<crate::enums::LogLevel>()?;
69    m.add_class::<crate::enums::LogFormat>()?;
70    m.add_class::<crate::logging::logger::LoggerConfig>()?;
71    m.add_class::<crate::logging::logger::LogGuard>()?;
72    m.add_class::<crate::logging::writer::FileWriterConfig>()?;
73    m.add_function(wrap_pyfunction!(logging::py_init_logging, m)?)?;
74    m.add_function(wrap_pyfunction!(logging::py_logger_flush, m)?)?;
75    m.add_function(wrap_pyfunction!(logging::py_logger_log, m)?)?;
76    m.add_function(wrap_pyfunction!(logging::py_log_header, m)?)?;
77    m.add_function(wrap_pyfunction!(logging::py_log_sysinfo, m)?)?;
78    m.add_function(wrap_pyfunction!(logging::py_logging_clock_set_static_mode, m)?)?;
79    m.add_function(wrap_pyfunction!(logging::py_logging_clock_set_realtime_mode, m)?)?;
80    m.add_function(wrap_pyfunction!(logging::py_logging_clock_set_static_time, m)?)?;
81    #[cfg(feature = "tracing-bridge")]
82    m.add_function(wrap_pyfunction!(logging::py_tracing_is_initialized, m)?)?;
83    #[cfg(feature = "tracing-bridge")]
84    m.add_function(wrap_pyfunction!(logging::py_init_tracing, m)?)?;
85    m.add_function(wrap_pyfunction!(xrate::py_get_exchange_rate, m)?)?;
86
87    #[cfg(feature = "live")]
88    m.add_class::<crate::live::listener::MessageBusListener>()?;
89
90    Ok(())
91}