| Crates.io | fusabi-stdlib-ext |
| lib.rs | fusabi-stdlib-ext |
| version | 0.1.6 |
| created_at | 2025-12-05 23:07:46.06043+00 |
| updated_at | 2025-12-09 04:51:47.01771+00 |
| description | Extended standard library modules and domain packs for Fusabi |
| homepage | |
| repository | https://github.com/fusabi-lang/fusabi-stdlib-ext |
| max_upload_size | |
| id | 1969377 |
| size | 263,800 |
Extended standard library modules for the Fusabi scripting language ecosystem.
Documentation: See versioned docs for detailed API reference and guides.
Latest Release: v0.1.0 | Changelog | Release Process
fusabi-stdlib-ext provides optional, safety-first standard library modules for Fusabi host applications. All modules implement capability-based security with configurable allowlists and resource limits.
process - Process execution (spawn, exec)fs - Filesystem operations (read, write, list, mkdir, remove)path - Path manipulation (join, dirname, basename, normalize)env - Environment variable accessformat - String formatting and JSON encode/decodenet - HTTP client (GET, POST)time - Time and duration utilitiesmetrics - Counter, gauge, and histogram metricsterminal - Terminal I/O: key events, selection, clipboard, palette helpersgpu - GPU metrics: NVML/DGX metrics shims for observabilityfs_stream - File streaming: tail files with backpressurenet_http - Enhanced HTTP: lightweight client with advanced timeout controlsterminal-ui - Terminal UI utilities (ANSI, prompts)observability - Logging, tracing, metrics integrationk8s - Kubernetes/cloud helpersmcp - MCP/AI tool integrationAdd to your Cargo.toml:
[dependencies]
fusabi-stdlib-ext = { version = "0.1", features = ["fs", "net", "time"] }
use std::sync::Arc;
use fusabi_stdlib_ext::{StdlibRegistry, StdlibConfig, SafetyConfig};
use fusabi_stdlib_ext::safety::{PathAllowlist, HostAllowlist};
use fusabi_host::Engine;
// Create safety configuration
let safety = Arc::new(
SafetyConfig::new()
.with_paths(PathAllowlist::none().allow("/tmp"))
.with_hosts(HostAllowlist::none().allow("api.example.com"))
);
// Create stdlib registry
let registry = StdlibRegistry::new(StdlibConfig::default(), safety);
// Register with engine
let mut engine = Engine::new();
registry.register_all(&mut engine);
use fusabi_stdlib_ext::fs;
use fusabi_stdlib_ext::safety::{SafetyConfig, PathAllowlist};
// Configure allowed paths
let safety = Arc::new(
SafetyConfig::new()
.with_paths(PathAllowlist::none().allow("/data"))
);
// Read a file
let content = fs::read_file(&safety, &[Value::String("/data/config.json".into())], &ctx)?;
// Write a file
fs::write_file(&safety, &[
Value::String("/data/output.txt".into()),
Value::String("Hello, World!".into()),
], &ctx)?;
// List directory
let entries = fs::list_dir(&safety, &[Value::String("/data".into())], &ctx)?;
use fusabi_stdlib_ext::net;
use fusabi_stdlib_ext::safety::{SafetyConfig, HostAllowlist};
use std::time::Duration;
// Configure allowed hosts
let safety = Arc::new(
SafetyConfig::new()
.with_hosts(HostAllowlist::none().allow("api.example.com"))
.with_default_timeout(Duration::from_secs(30))
);
// GET request
let response = net::http_get(
&safety,
Some(Duration::from_secs(10)),
&[Value::String("https://api.example.com/data".into())],
&ctx,
)?;
// POST request
let response = net::http_post(
&safety,
None,
&[
Value::String("https://api.example.com/submit".into()),
Value::String(r#"{"key": "value"}"#.into()),
],
&ctx,
)?;
use fusabi_stdlib_ext::process;
use fusabi_stdlib_ext::safety::{SafetyConfig, CommandAllowlist};
// Configure allowed commands
let safety = Arc::new(
SafetyConfig::new()
.with_commands(CommandAllowlist::none().allow("ls").allow("cat"))
);
// Execute command and wait for result
let result = process::exec(
&safety,
Some(Duration::from_secs(5)),
&[
Value::String("ls".into()),
Value::List(vec![Value::String("-la".into())]),
],
&ctx,
)?;
// Spawn background process
let handle = process::spawn(
&safety,
&[Value::String("long-running-task".into())],
&ctx,
)?;
use fusabi_stdlib_ext::metrics;
// Increment a counter
metrics::counter_inc(&[Value::String("requests_total".into())], &ctx)?;
metrics::counter_inc(&[Value::String("requests_total".into()), Value::Int(5)], &ctx)?;
// Set a gauge
metrics::gauge_set(&[
Value::String("active_connections".into()),
Value::Float(42.0),
], &ctx)?;
// Observe histogram value
metrics::histogram_observe(&[
Value::String("request_duration_seconds".into()),
Value::Float(0.235),
], &ctx)?;
use fusabi_stdlib_ext::time;
// Get current timestamp
let now = time::now(&[], &ctx)?; // Unix seconds
let now_ms = time::now_millis(&[], &ctx)?; // Unix milliseconds
// Sleep
time::sleep(&[Value::Int(1000)], &ctx)?; // Sleep 1 second
// Format timestamp
let formatted = time::format_time(&[
Value::Int(1704067200),
Value::String("%Y-%m-%d".into()),
], &ctx)?;
use fusabi_stdlib_ext::format;
// Sprintf-style formatting
let result = format::sprintf(&[
Value::String("Hello, %s! You have %d messages.".into()),
Value::String("Alice".into()),
Value::Int(5),
], &ctx)?;
// Template substitution
let mut values = HashMap::new();
values.insert("name".into(), Value::String("Bob".into()));
let result = format::template(&[
Value::String("Hello, {{name}}!".into()),
Value::Map(values),
], &ctx)?;
// JSON encode/decode
let json = format::json_encode(&[value], &ctx)?;
All modules follow a default-deny security model:
use fusabi_stdlib_ext::safety::PathAllowlist;
// Deny all paths (default)
let paths = PathAllowlist::none();
// Allow specific paths
let paths = PathAllowlist::none()
.allow("/data")
.allow("/tmp");
// Allow all paths (use with caution)
let paths = PathAllowlist::all();
use fusabi_stdlib_ext::safety::HostAllowlist;
// Deny all hosts (default)
let hosts = HostAllowlist::none();
// Allow specific hosts
let hosts = HostAllowlist::none()
.allow("api.example.com")
.allow("cdn.example.com");
// Allow all hosts (use with caution)
let hosts = HostAllowlist::all();
use fusabi_stdlib_ext::SafetyConfig;
use std::time::Duration;
let safety = SafetyConfig::new()
.with_default_timeout(Duration::from_secs(30))
.with_max_timeout(Duration::from_secs(300));
See CODEOWNERS for code ownership and review requirements.
All contributions must:
MIT OR Apache-2.0