32 releases (19 breaking)

new 0.21.0 Nov 14, 2024
0.19.0 Nov 12, 2024
0.14.0 Jul 26, 2024
0.1.0 Mar 6, 2024

#45 in Programming languages

Download history 3751/week @ 2024-07-25 3993/week @ 2024-08-01 2646/week @ 2024-08-08 3068/week @ 2024-08-15 3692/week @ 2024-08-22 3458/week @ 2024-08-29 3249/week @ 2024-09-05 2744/week @ 2024-09-12 2585/week @ 2024-09-19 2641/week @ 2024-09-26 2854/week @ 2024-10-03 3326/week @ 2024-10-10 2810/week @ 2024-10-17 3468/week @ 2024-10-24 4126/week @ 2024-10-31 3396/week @ 2024-11-07

14,403 downloads per month
Used in 8 crates (5 directly)

BSD-3-Clause

125KB
2.5K SLoC

runtimelib

runtimelib is a Rust library for interacting with Jupyter kernels and managing interactive computing environments. It provides a set of tools and abstractions to simplify the process of working with various programming language runtimes, enabling developers to build powerful applications that leverage the capabilities of Jupyter kernels.

Introduction

runtimelib serves as the foundation for building interactive computing applications, REPLs, and notebook-like interfaces. It abstracts away the complexities of communicating with Jupyter kernels, allowing developers to focus on creating rich, interactive experiences for users.

Key features of runtimelib include:

  • Easy integration with Jupyter kernels
  • Asynchronous communication with kernels
  • Support for multiple runtime environments
  • Extensible architecture for custom kernel implementations

Whether you're building a new notebook application, creating a specialized REPL, or integrating interactive computing capabilities into your existing projects, runtimelib provides the tools and flexibility you need to get started quickly and efficiently.

Installation

Add this to your Cargo.toml:

[dependencies]
runtimelib = "0.15.1"

By default, RuntimeLib uses Tokio as its async runtime. If you want to use the async-dispatcher runtime instead, you can enable it with the following feature flag:

[dependencies]
runtimelib = { version = "0.15.1", features = ["async-dispatcher-runtime"] }

Key Features

  • Jupyter Kernel Management: Discover, start, and manage Jupyter kernels.
  • Messaging Protocol: Implement the Jupyter messaging protocol for communication with kernels.
  • Runtime Management: Create and manage runtime instances for interactive computing.
  • Flexible Async Runtime: Support for both Tokio and async-dispatcher runtimes.
  • Media Handling: Work with various media types used in Jupyter, including images, HTML, and more.

Usage Example

Here's a simple example of how to use RuntimeLib to start a Jupyter kernel and execute some code:

use runtimelib::jupyter::{client::JupyterRuntime, KernelspecDir};
use runtimelib::messaging::{ExecuteRequest, JupyterMessage};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Find and start a Python kernel
    let kernelspec = KernelspecDir::new(&"python3".to_string()).await?;
    let runtime = JupyterRuntime::new(kernelspec).await?;

    // Attach to the runtime
    let mut client = runtime.attach().await?;

    // Execute some Python code
    let execute_request = ExecuteRequest::new("print('Hello, World!')".to_string());
    let message: JupyterMessage = execute_request.into();
    let response = client.send(message).await?;

    println!("Execution response: {:?}", response);

    Ok(())
}

This example demonstrates how to start a Python kernel, attach to it, and execute a simple Python command.

Documentation

For more detailed information about the API and its usage, please refer to the API documentation.

Contributing

We welcome contributions to RuntimeLib! If you'd like to contribute, please:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Write tests for your changes
  4. Implement your changes
  5. Submit a pull request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

RuntimeLib is distributed under the terms of both the MIT license and the Apache License (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~13–27MB
~499K SLoC