Expand description
Standard Python Runtime Library for Rython
This library provides all the built-in functions, types, and methods that are available in Python without any imports. It serves as the runtime foundation for Python code compiled to Rust using python-ast-rs.
§Features
std
(default): Full standard library support with I/O operationsnostd
: No-std compatible version for embedded systems
Re-exports§
pub use stdlib::sys;
pub use stdlib::os;
pub use stdlib::subprocess;
pub use stdlib::sysconfig;
pub use stdlib::venv;
pub use stdlib::math;
pub use stdlib::random;
pub use stdlib::datetime;
pub use stdlib::string;
pub use stdlib::json;
pub use stdlib::collections;
pub use stdlib::itertools;
pub use stdlib::pathlib;
pub use stdlib::tempfile;
pub use stdlib::glob;
pub use math::ceil_py;
pub use math::ceil_wrapper;
pub use math::floor_py;
pub use math::floor_wrapper;
pub use math::trunc_py;
pub use math::trunc_wrapper;
pub use math::fabs_py;
pub use math::fabs_wrapper;
pub use math::sqrt_py;
pub use math::sqrt_wrapper;
pub use math::pow_py;
pub use math::pow_wrapper;
pub use math::exp_py;
pub use math::exp_wrapper;
pub use math::exp2_py;
pub use math::exp2_wrapper;
pub use math::expm1_py;
pub use math::expm1_wrapper;
pub use math::log_py;
pub use math::log_wrapper;
pub use math::log2_py;
pub use math::log2_wrapper;
pub use math::log10_py;
pub use math::log10_wrapper;
pub use math::log1p_py;
pub use math::log1p_wrapper;
pub use math::sin_py;
pub use math::sin_wrapper;
pub use math::cos_py;
pub use math::cos_wrapper;
pub use math::tan_py;
pub use math::tan_wrapper;
pub use math::asin_py;
pub use math::asin_wrapper;
pub use math::acos_py;
pub use math::acos_wrapper;
pub use math::atan_py;
pub use math::atan_wrapper;
pub use math::atan2_py;
pub use math::atan2_wrapper;
pub use math::sinh_py;
pub use math::sinh_wrapper;
pub use math::cosh_py;
pub use math::cosh_wrapper;
pub use math::tanh_py;
pub use math::tanh_wrapper;
pub use math::asinh_py;
pub use math::asinh_wrapper;
pub use math::acosh_py;
pub use math::acosh_wrapper;
pub use math::atanh_py;
pub use math::atanh_wrapper;
pub use math::degrees_py;
pub use math::degrees_wrapper;
pub use math::radians_py;
pub use math::radians_wrapper;
pub use math::factorial_py;
pub use math::factorial_wrapper;
pub use math::gcd_py;
pub use math::gcd_wrapper;
pub use math::lcm_py;
pub use math::lcm_wrapper;
pub use math::isfinite_py;
pub use math::isfinite_wrapper;
pub use math::isinf_py;
pub use math::isinf_wrapper;
pub use math::isnan_py;
pub use math::isnan_wrapper;
pub use math::isclose_py;
pub use math::isclose_wrapper;
pub use math::copysign_py;
pub use math::copysign_wrapper;
pub use math::frexp_py;
pub use math::frexp_wrapper;
pub use math::ldexp_py;
pub use math::ldexp_wrapper;
pub use math::modf_py;
pub use math::modf_wrapper;
pub use math::fmod_py;
pub use math::fmod_wrapper;
pub use math::remainder_py;
pub use math::remainder_wrapper;
pub use random::seed_py;
pub use random::seed_wrapper;
pub use random::getstate_py;
pub use random::getstate_wrapper;
pub use random::random_py;
pub use random::random_wrapper;
pub use random::uniform_py;
pub use random::uniform_wrapper;
pub use random::triangular_py;
pub use random::triangular_wrapper;
pub use json::loads_py;
pub use json::loads_wrapper;
pub use json::dumps_py;
pub use json::dumps_wrapper;
pub use json::load_py;
pub use json::load_wrapper;
pub use json::dump_py;
pub use json::dump_wrapper;
pub use os::execv_mixed_py;
pub use os::execv_mixed_wrapper;
pub use os::getenv_py;
pub use os::getenv_wrapper;
pub use os::setenv_py;
pub use os::setenv_wrapper;
pub use os::getcwd_py;
pub use os::getcwd_wrapper;
pub use os::chdir_py;
pub use os::chdir_wrapper;
pub use os::path::dirname_py;
pub use os::path::dirname_wrapper;
pub use os::path::basename_py;
pub use os::path::basename_wrapper;
pub use os::path::join_py;
pub use os::path::join_wrapper;
pub use os::path::exists_py;
pub use os::path::exists_wrapper;
pub use os::path::isfile_py;
pub use os::path::isfile_wrapper;
pub use os::path::isdir_py;
pub use os::path::isdir_wrapper;
pub use os::path::abspath_py;
pub use os::path::abspath_wrapper;
pub use os::path::relpath_py;
pub use os::path::relpath_wrapper;
pub use sys::exit_py;
pub use sys::exit_wrapper;
pub use sys::platform_py;
pub use sys::platform_wrapper;
pub use sys::version_py;
pub use sys::version_wrapper;
pub use sys::get_executable_py;
pub use sys::get_executable_wrapper;
pub use sys::get_argv_py;
pub use sys::get_argv_wrapper;
pub use sys::get_platform_py;
pub use sys::get_platform_wrapper;
pub use string::capwords_py;
pub use string::capwords_wrapper;
pub use collections::counter_py;
pub use collections::counter_wrapper;
pub use collections::create_deque_py;
pub use collections::create_deque_wrapper;
pub use collections::defaultdict_int_py;
pub use collections::defaultdict_int_wrapper;
pub use collections::defaultdict_list_py;
pub use collections::defaultdict_list_wrapper;
pub use subprocess::run_py;
pub use subprocess::run_wrapper;
pub use subprocess::call_py;
pub use subprocess::call_wrapper;
pub use subprocess::check_call_py;
pub use subprocess::check_call_wrapper;
pub use subprocess::check_output_py;
pub use subprocess::check_output_wrapper;
Modules§
- python_
signature - Custom Python signature system that preserves generic parameters
- stdlib
- Python Standard Library modules Python Standard Library Implementation
Macros§
- impl_
python_ module - Macro to implement PythonModule for stdlib modules
- python_
function - More advanced macro that can handle complex signatures with defaults
- python_
signature - Custom Python signature system that allows generic parameters
- register_
python_ module - Convenience macro to register a module’s Python functions
Structs§
- PyAny
- Represents any Python object.
- PyDictionary
- Python-style dictionary type with all dict methods
- PyException
- Base class for all Python exceptions
- PyFile
- Python file object
- PyList
- Python-style list type with all list methods
- PySet
- Python-style set type with all set methods
- PyStr
- Python-style string type with all string methods
- PyTuple
- Python-style tuple type
Constants§
Traits§
- AsArg
List - Trait for collections that can be used as argument lists
- AsEnv
Like - Trait for environment-like collections (key-value pairs)
- AsPath
Like - Trait for types that can be used as path-like parameters
- AsStr
Like - Trait for types that can be used as string-like parameters
- Into
Owned String - Trait for types that can be converted to owned strings
- Len
- Trait for objects that have a length
- PyAbs
- Trait for types that support absolute value
- PyBool
- Trait for Python-style boolean conversion
- PyFloat
- Trait for Python-style float conversion
- PyInt
- Trait for Python-style integer conversion
- PySum
- Trait for types that can be summed
- PyTo
String - Trait for Python-style string conversion
- Truthy
- Trait for objects that can be evaluated for truthiness
Functions§
- abs
- Python abs() function - returns absolute value
- all
- Python all() function - returns True if all elements are truthy
- any
- Python any() function - returns True if any element is truthy
- attribute_
error - Python AttributeError
- bool
- Python bool() function - converts to boolean
- dict
- Python dict() function - creates a new dictionary (generic version)
- dict_
from_ pairs - Simplified dict creation from key-value pairs
- dict_
with_ env - Python dict() function with environment merging (generic version)
- ensure_
venv_ ready - Placeholder for ensure_venv_ready function (from pyperformance or similar) This is not a standard Python built-in, so we provide a stub that returns dummy values
- enumerate
- Python enumerate() function - returns iterator with index and value pairs
- enumerate_
slice - Helper for enumerate() function with slice input - returns pairs of (index, reference)
- float
- Python float() function - converts to float
- format_
string - Helper for string formatting (common in f-strings compilation)
- index_
error - Python IndexError
- input
- Python input() function - reads input from user
- int
- Python int() function - converts to integer
- key_
error - Python KeyError
- len
- Python len() function - returns the length of an object
- list_
contains - Helper for in/not in operations on lists
- max
- Python max() function
- min
- Python min() function
- multiply_
list - Helper for Python-style list multiplication
- multiply_
string - Helper for Python-style string multiplication
- name_
error - Python NameError
- open
- Python open() function - opens a file
- overflow_
error - Python OverflowError
- Python print() function - outputs objects to stdout with optional separator and ending
- print_
args - Python print() function with multiple arguments
Note: Only available with
std
feature - requires OS I/O capabilities - py_dict
- Helper function for dictionary creation (common in compiled code)
- py_list
- Helper function for list creation from Rust vectors (common in compiled code)
- py_set
- Helper function for set creation (common in compiled code)
- py_
tuple - Helper function for tuple creation (common in compiled code)
- range
- Python range() function - generates sequence of numbers
- range_
flexible - Helper for range() function with optional parameters - more flexible than the basic range
- range_
start_ stop - range_
start_ stop_ step - runtime_
error - Python RuntimeError
- slice
- Helper for Python-style slicing
- str
- Python str() function - converts to string
- string_
contains - Helper for in/not in operations on strings
- sum
- Python sum() function
- type_
error - Python TypeError
- value_
error - Python ValueError
- zero_
division_ error - Python ZeroDivisionError
- zip
- Python zip() function - combines multiple iterables
- zip_
slices - Helper for zip() function with slice inputs - combines two iterables with lifetimes
Type Aliases§
- PyObject
- A commonly-used alias for
Py<PyAny>
.