Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/switchyard-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_json = "1"
switchyard-core = { path = "../switchyard-core" }
switchyard-components = { path = "../switchyard-components" }
switchyard-components-v2 = { path = "../switchyard-components-v2" }
switchyard-protocol = { path = "../libsy-protocol" }
switchyard-server = { path = "../switchyard-server" }
switchyard-translation = { path = "../switchyard-translation" }
tokio = { version = "1", features = ["rt", "rt-multi-thread", "sync"] }
Expand Down
7 changes: 7 additions & 0 deletions crates/switchyard-py/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use switchyard_core::SwitchyardError;
use switchyard_translation::TranslationError;

create_exception!(_switchyard_rust, SwitchyardRuntimeError, PyRuntimeError);
create_exception!(_switchyard_rust, LibsyError, SwitchyardRuntimeError);
create_exception!(
_switchyard_rust,
SwitchyardConfigError,
Expand Down Expand Up @@ -79,6 +80,11 @@ pub(crate) fn py_translation_error(error: TranslationError) -> PyErr {
PyValueError::new_err(format!("{}: {}", error.kind(), error))
}

/// Converts libsy orchestration failures into the Python binding error.
pub(crate) fn py_libsy_error(error: impl std::fmt::Display) -> PyErr {
LibsyError::new_err(error.to_string())
}

/// Converts core Switchyard errors into typed Python runtime errors.
///
/// `ContextWindowExceeded` and `ContextPoolExhausted` carry typed fields
Expand Down Expand Up @@ -161,6 +167,7 @@ pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
"SwitchyardRuntimeError",
py.get_type::<SwitchyardRuntimeError>(),
)?;
module.add("LibsyError", py.get_type::<LibsyError>())?;
module.add(
"SwitchyardConfigError",
py.get_type::<SwitchyardConfigError>(),
Expand Down
2 changes: 2 additions & 0 deletions crates/switchyard-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use pyo3::prelude::*;
mod component_bindings;
mod core_bindings;
mod errors;
mod libsy_bindings;
mod profile_bindings;
mod py_serde;
mod server_bindings;
Expand All @@ -14,6 +15,7 @@ mod translation;
#[pymodule]
fn _switchyard_rust(module: &Bound<'_, PyModule>) -> PyResult<()> {
errors::register(module)?;
libsy_bindings::register(module)?;
translation::register(module)?;
core_bindings::register(module)?;
component_bindings::register(module)?;
Expand Down
18 changes: 18 additions & 0 deletions crates/switchyard-py/src/libsy_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Python bindings for Switchyard's neutral LLM protocol values.

mod protocol;
mod values;

use pyo3::prelude::*;

pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
let protocol_module = PyModule::new(module.py(), "libsy_protocol")?;
protocol::register(&protocol_module)?;
values::register(&protocol_module)?;
module.add_submodule(&protocol_module)?;

Ok(())
}
Loading
Loading