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;

Modules§

stdlib
Python Standard Library modules Python Standard Library Implementation

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>.