| Crates.io | stdpython |
| lib.rs | stdpython |
| version | 1.0.8 |
| created_at | 2025-08-05 21:54:50.610523+00 |
| updated_at | 2025-08-07 17:46:57.384483+00 |
| description | Python standard library runtime for the Rython compiler ecosystem |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1783122 |
| size | 340,194 |
The default Python runtime library for the Rython compiler ecosystem. This crate provides a comprehensive, Python-compatible standard library implementation in Rust that serves as the runtime foundation for Python code compiled to Rust via the Rython toolchain.
rython_stdpython is a complete Python runtime environment written in Rust that enables compiled Python code to access all Python built-ins, types, and standard operations without requiring any imports. It provides both std and no_std variants, making it suitable for everything from desktop applications to embedded systems.
print, len, range, enumerate, zip, min, max, sum, all, any, etc.)str, list, dict, tuple, set, int, float, bool with all their methodsValueError, TypeError, IndexError, etc.)This library uses a generic trait-based design that mirrors Python's built-in behavior:
PyAbs: Generic absolute value (abs(-5i64), abs(-3.14f64))PyBool: Generic boolean conversion (bool(42), bool(""))PyInt: Generic integer conversion (int("123"), int(3.14))PyFloat: Generic float conversion (float("3.14"), float(42))PyToString: Generic string conversion (str(123), str(true))PySum: Generic summation (sum(&[1,2,3]), sum(&pylist))Len: Universal length calculationTruthy: Python-style truthiness evaluation✅ Math/Logic: abs(), min(), max(), sum(), all(), any()
✅ Iteration: enumerate(), zip(), range(), len()
✅ Type Conversion: bool(), int(), float(), str(), list(), dict(), tuple(), set()
✅ Object Introspection: type(), isinstance(), hasattr(), getattr(), setattr(), delattr(), id(), hash()
✅ Character/Unicode: ord(), chr()
✅ I/O: print() with full parameter support (std mode only)
✅ Core Methods: split(), join(), strip(), lower(), upper(), replace()
✅ Search Methods: find(), count(), startswith(), endswith()
✅ Formatting: format() (basic implementation)
✅ Modification: append(), extend(), insert(), remove(), pop(), clear()
✅ Search/Sort: index(), count(), sort(), reverse()
✅ Utilities: copy(), indexing with get()/set()
✅ Access: get(), get_or_default(), contains_key()
✅ Modification: set(), pop(), clear(), update()
✅ Iteration: keys(), values(), items()
✅ Immutable sequence: Index access, slicing support
✅ Modification: add(), remove(), discard(), clear()
✅ Set Operations: union(), intersection(), difference()
✅ Membership: contains()
✅ Complete Exception Hierarchy: PyException, ValueError, TypeError, IndexError, KeyError, AttributeError, NameError, ZeroDivisionError, OverflowError, RuntimeError
❌ Advanced Python Features: Decorators, metaclasses, generators, async/await
❌ Complex Built-ins: exec(), eval(), compile(), globals(), locals()
❌ File I/O (no_std mode): File operations, directory handling
❌ Networking: Socket operations, HTTP clients
❌ Threading: Thread management, locks, synchronization
❌ Regular Expressions: re module functionality
❌ Date/Time: datetime, time module functionality
❌ OS Interface: os, sys module functionality
❌ Import System: Dynamic module loading
[dependencies]
rython_stdpython = "1.0"
[dependencies]
rython_stdpython = { version = "1.0", default-features = false, features = ["nostd"] }
use rython_stdpython::*;
fn main() {
// Generic functions work with any compatible type
let nums = vec![1, 2, 3, 4, 5];
let total = sum(&nums[..]); // Generic summation
// Python-like type conversions
let s = str(total); // "15"
let b = bool(&nums); // true (non-empty)
// Full Python collections
let mut list = PyList::from_vec(nums);
list.append(6);
// All Python built-ins available
print(&format!("Total: {}", total));
assert_eq!(len(&list), 6);
}
This crate serves as the runtime foundation for the entire Rython ecosystem:
When Python code is compiled to Rust, it naturally maps to function calls in this library:
# Python code
my_list = [1, 2, 3]
total = sum(my_list)
print(str(total))
// Generated Rust code
let mut my_list = PyList::from_vec(vec![1, 2, 3]);
let total = sum(&my_list); // Uses PySum trait
print(str(total)); // Uses PyToString trait
# Standard library version
cargo build
cargo test
# No-std version
cargo build --no-default-features --features nostd
cargo test --no-default-features --features nostd
# Run specific test modules
cargo test test_python_functions # Built-in function tests
cargo test test_pystr # String type tests
cargo test test_pylist # List type tests
This project is part of the Rython compiler ecosystem.