Expand description
§py2pyd
A Rust library for compiling Python modules to pyd/so extension files.
This library provides programmatic access to py2pyd’s compilation capabilities, allowing you to integrate Python-to-pyd compilation into your own Rust projects.
§Features
- Compile single Python files to pyd/so extensions
- Batch compile multiple Python files
- Support for uv-based Python environment management
- Automatic build tools detection (MSVC, MinGW, GCC, Xcode)
- Python AST parsing and transformation
§Example
use py2pyd::{compile_file, CompileConfig};
use std::path::Path;
fn main() -> anyhow::Result<()> {
let config = CompileConfig::default();
compile_file(
Path::new("input.py"),
Path::new("output.pyd"),
&config,
)?;
Ok(())
}Re-exports§
pub use build_tools::check_build_tools;pub use build_tools::detect_build_tools;pub use build_tools::BuildTools;pub use compiler::batch_compile as compiler_batch_compile;pub use compiler::compile_file as compiler_compile_file;pub use parser::extract_classes;pub use parser::extract_from_imports;pub use parser::extract_functions;pub use parser::extract_imports;pub use parser::extract_module_vars;pub use parser::parse_file;pub use parser::parse_source;pub use transformer::generate_cargo_toml;pub use transformer::transform_ast;pub use transformer::transform_file;pub use transformer::TransformedModule;pub use uv_compiler::CompileConfig;pub use uv_env::UvEnv;pub use uv_env::UvEnvConfig;
Modules§
Functions§
- batch_
compile - Batch compile multiple Python files to pyd/so extensions.
- batch_
compile_ legacy - Batch compile using the legacy compiler (without uv).
- compile_
file - Compile a single Python file to a pyd/so extension using uv-based compilation.
- compile_
file_ legacy - Compile a Python file using the legacy compiler (without uv).
- create_
uv_ env - Create a new uv-based Python virtual environment.
- get_
extension - Get the appropriate extension for compiled Python modules on the current platform.
- verify_
build_ tools - Check if the required build tools are available on the system.