nautilus_core/python/
mod.rspub mod casing;
pub mod datetime;
pub mod serialization;
pub mod uuid;
pub mod version;
use pyo3::{
exceptions::{PyRuntimeError, PyTypeError, PyValueError},
prelude::*,
types::PyString,
wrap_pyfunction,
};
use crate::{
datetime::{
MILLISECONDS_IN_SECOND, NANOSECONDS_IN_MICROSECOND, NANOSECONDS_IN_MILLISECOND,
NANOSECONDS_IN_SECOND,
},
uuid::UUID4,
version::{NAUTILUS_VERSION, USER_AGENT},
};
pub fn get_pytype_name<'py>(obj: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyString>> {
obj.get_type().name()
}
pub fn to_pyvalue_err(e: impl std::fmt::Display) -> PyErr {
PyValueError::new_err(e.to_string())
}
pub fn to_pytype_err(e: impl std::fmt::Display) -> PyErr {
PyTypeError::new_err(e.to_string())
}
pub fn to_pyruntime_err(e: impl std::fmt::Display) -> PyErr {
PyRuntimeError::new_err(e.to_string())
}
#[pymodule]
#[rustfmt::skip]
pub fn core(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add(stringify!(NAUTILUS_VERSION), NAUTILUS_VERSION)?;
m.add(stringify!(USER_AGENT), USER_AGENT)?;
m.add(stringify!(MILLISECONDS_IN_SECOND), MILLISECONDS_IN_SECOND)?;
m.add(stringify!(NANOSECONDS_IN_SECOND), NANOSECONDS_IN_SECOND)?;
m.add(stringify!(NANOSECONDS_IN_MILLISECOND), NANOSECONDS_IN_MILLISECOND)?;
m.add(stringify!(NANOSECONDS_IN_MICROSECOND), NANOSECONDS_IN_MICROSECOND)?;
m.add_class::<UUID4>()?;
m.add_function(wrap_pyfunction!(casing::py_convert_to_snake_case, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_secs_to_nanos, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_secs_to_millis, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_millis_to_nanos, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_micros_to_nanos, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_nanos_to_secs, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_nanos_to_millis, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_nanos_to_micros, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_unix_nanos_to_iso8601, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_last_weekday_nanos, m)?)?;
m.add_function(wrap_pyfunction!(datetime::py_is_within_last_24_hours, m)?)?;
Ok(())
}