Rust
and
Python
John Vandenberg https://github.com/jayvdb
08/09/23
2
RustPython
●
https://rustpython.github.io/
●
Started May 2018
●
Version 0.2 released January 2023
●
Includes standard library written in Rust
●
70% of the CPython 3.11 test suite passes
●
pip works
●
RustPython can be compiled to WebAssembly, allowing running Python
code in the web browser
●
Has an experimental JIT compiler to compile python to native code
08/09/23
3
Python packaging
●
https://github.com/PyO3 (Pythonium Trioxide)
●
setuptools-rust
– 50,000 downloads per day
– https://github.com/PyO3/setuptools-rust
●
maturin
– 20,000 downloads per day
– https://github.com/PyO3/maturin
08/09/23
4
Python packages
●
Cryptography – Using setuptools-rust
– 7 million downloads per day
– Approx 15th
most downloaded package
– https://github.com/pyca/cryptography
●
Pydantic - Using maturin
– 3 million downloads per day
– https://github.com/pydantic/pydantic-core
●
Rpds-py - Using maturin
– 2 million downloads per day (dep of jsonschema)
– https://github.com/crate-py/rpds
jsonschema-rs will be
on this list soon.
08/09/23
5
Python packages
●
orjson – Using maturin
– 500,000 downloads per day
– https://github.com/ijl/orjson
●
LibCST - Using setuptools-rust
– 250,000 downloads per day
– https://github.com/Instagram/LibCST
●
Ruff (Python linter) - Using maturin
– 175,000 downloads per day
●
polars - Using maturin
– 50,000 downloads per day
– https://github.com/pola-rs/polars
08/09/23
6
result
from result import Result, Ok, Err
def divide(a: int, b: int) -> Result[int, str]:
if b == 0:
return Err("Cannot divide by zero")
return Ok(a // b)
values = [(10, 0), (10, 5)]
for a, b in values:
divide_result = divide(a, b)
match divide_result:
case Ok(value):
print(f"{a} // {b} == {value}")
case Err(e):
print(e)
https://github.com/rustedpy/result
4k downloads/day
08/09/23
7
PyOxidizer
●
https://github.com/indygreg/PyOxidizer
●
Combines CPython runtime, Python code and dependencies into a single
executable
●
Supports Windows, Linux and Mac executable formats
●
Also creates installers for Windows, Linux and Mac
●
Pyembed crate controls an embedded CPython inside Rust
08/09/23
8
Python tools
●
Package managers like pipenv, poetry, etc
– https://github.com/mitsuhiko/rye
●
Also includes Python runtime management, like pyenv
– https://github.com/cnpryer/huak
●
Incomplete and not as actively developed
●
Vulnerability scanner
– https://github.com/aswinnnn/pyscan
●
Static code analysis
– Ruff
– https://github.com/mtshiba/pylyzer
08/09/23
9
py2many
●
https://github.com/py2many/py2many
●
Transpiles subset of Python to:
– C++, Dart, Go, Julia, Kotlin, Nim, Rust, V
●
Supports CLI sys.argv and sys.stdout

Rust & Python : Rust WA meetup 1

  • 1.
  • 2.
    08/09/23 2 RustPython ● https://rustpython.github.io/ ● Started May 2018 ● Version0.2 released January 2023 ● Includes standard library written in Rust ● 70% of the CPython 3.11 test suite passes ● pip works ● RustPython can be compiled to WebAssembly, allowing running Python code in the web browser ● Has an experimental JIT compiler to compile python to native code
  • 3.
    08/09/23 3 Python packaging ● https://github.com/PyO3 (PythoniumTrioxide) ● setuptools-rust – 50,000 downloads per day – https://github.com/PyO3/setuptools-rust ● maturin – 20,000 downloads per day – https://github.com/PyO3/maturin
  • 4.
    08/09/23 4 Python packages ● Cryptography –Using setuptools-rust – 7 million downloads per day – Approx 15th most downloaded package – https://github.com/pyca/cryptography ● Pydantic - Using maturin – 3 million downloads per day – https://github.com/pydantic/pydantic-core ● Rpds-py - Using maturin – 2 million downloads per day (dep of jsonschema) – https://github.com/crate-py/rpds jsonschema-rs will be on this list soon.
  • 5.
    08/09/23 5 Python packages ● orjson –Using maturin – 500,000 downloads per day – https://github.com/ijl/orjson ● LibCST - Using setuptools-rust – 250,000 downloads per day – https://github.com/Instagram/LibCST ● Ruff (Python linter) - Using maturin – 175,000 downloads per day ● polars - Using maturin – 50,000 downloads per day – https://github.com/pola-rs/polars
  • 6.
    08/09/23 6 result from result importResult, Ok, Err def divide(a: int, b: int) -> Result[int, str]: if b == 0: return Err("Cannot divide by zero") return Ok(a // b) values = [(10, 0), (10, 5)] for a, b in values: divide_result = divide(a, b) match divide_result: case Ok(value): print(f"{a} // {b} == {value}") case Err(e): print(e) https://github.com/rustedpy/result 4k downloads/day
  • 7.
    08/09/23 7 PyOxidizer ● https://github.com/indygreg/PyOxidizer ● Combines CPython runtime,Python code and dependencies into a single executable ● Supports Windows, Linux and Mac executable formats ● Also creates installers for Windows, Linux and Mac ● Pyembed crate controls an embedded CPython inside Rust
  • 8.
    08/09/23 8 Python tools ● Package managerslike pipenv, poetry, etc – https://github.com/mitsuhiko/rye ● Also includes Python runtime management, like pyenv – https://github.com/cnpryer/huak ● Incomplete and not as actively developed ● Vulnerability scanner – https://github.com/aswinnnn/pyscan ● Static code analysis – Ruff – https://github.com/mtshiba/pylyzer
  • 9.
    08/09/23 9 py2many ● https://github.com/py2many/py2many ● Transpiles subset ofPython to: – C++, Dart, Go, Julia, Kotlin, Nim, Rust, V ● Supports CLI sys.argv and sys.stdout