Crate stdpython

Source
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 operations
  • nostd: 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§

__file__
Python special variables
__name__

Traits§

AsArgList
Trait for collections that can be used as argument lists
AsEnvLike
Trait for environment-like collections (key-value pairs)
AsPathLike
Trait for types that can be used as path-like parameters
AsStrLike
Trait for types that can be used as string-like parameters
IntoOwnedString
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
PyToString
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
print
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>.