rust-to-python

A mapping of Rust features and tooling to Python

MIT License

Stars
8

Rust to Python

This repository provides a mapping from Rust tooling and language features to Python.

Tooling

Tool Rust Python
Package Repository crates.io PyPI
Multi-version Installation rustup uv python command
Package Management Cargo Poetry, uv
Build Executables Cargo PyInstaller
Type Checking Cargo Mypy
Code Formatting Rustfmt Ruff Formatter, Ruff isort rules
Linting Clippy Ruff
Unit Testing #[test] pytest
Scripts cargo-script uv run, Nox
Upgrade to New Language Features cargo fix Ruff pyupgrade rules

For a Python project example that incorporates these tools, see python-blueprint.

Environments

Environment Rust Python
WASM wasm-pack PyScript, Pyodide, CPython WASM
Embedded Embedded Rust MicroPython, CircuitPython

Language Features

Feature Rust Python
Interface trait Protocol
Generics <T> list[T] etc., def f[T], class C[T]
Pattern Matching match match
Anonymous Function |x| { x + 1 } lambda x: x + 1
Foreign Function Interface FFI CFFI

Data Structures

Data Structure Rust Python
Data Type struct @dataclass
Algebraic Data Type enum Enum, Union of dataclass
Result Result returns.Result
Optional Option T | None, returns.Maybe
Fixed-sized Numerics u8, u16, etc. NumPy Data Types

Rust/Python Interop

Popular Python Packages Implemented in Rust

Misc Rust and Python Similarities

  • Both languages prefer snake_case naming over lowerCamelCase
  • Both languages use suffix type syntax (e.g. x: int / x: i32)
  • Neither language is controlled by a single company