Ep 40. Rust 和 PyO3:让 Python 再次伟大 🦀 ❤️ 🐍捕蛇者说

Ep 40. Rust 和 PyO3:让 Python 再次伟大 🦀 ❤️ 🐍

77分钟 ·
播放数2023
·
评论数14

嘉宾

Messense

主播

链接

  • PyO3

  • PyO3 有哪些应用?

    • polars: Fast multi-threaded DataFrame library in Rust | Python | Node.js.
    • pydantic-core: Core validation logic for pydantic written in Rust.
    • cryptography: Python cryptography library with some functionality in Rust.
    • orjson: Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
  • PyO3 前身:rust-cpython

  • Maturin: Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages

  • What Are Python Wheels and Why Should You Care?

  • PEP 517 – A build-system independent format for source trees

  • Ruff: An extremely fast Python linter, written in Rust.

  • typos: Source code spell checker

  • ChatGPT 写的 Rust 调用 Python C-API 的例子

    use std::os::raw::{c_char, c_int};
    use std::ffi::CString;
    use libc::{c_double, c_void};
    #[link(name = "python3.8")]
    extern "C" {
    fn Py_Initialize();
    fn Py_Finalize();
    fn Py_BuildValue(format: *const c_char, ...) -> *mut c_void;
    }
    fn main() {
    unsafe {
    // 初始化 Python 解释器
    Py_Initialize();
    // 构建一个 Python 元组对象,并打印它
    let x = 1.23 as c_double;
    let y = 4.56 as c_double;
    let format = CString::new("dd").unwrap().as_ptr();
    let result = Py_BuildValue(format, x, y);
    let s = CString::from_raw(result as *mut c_char).into_string().unwrap();
    println!("{}", s);
    // 关闭 Python 解释器
    Py_Finalize();
    }
    }
  • pyo3-ffi: Python-API bindings for the PyO3 ecosystem

  • 在 PyO3 里通过 allow_threads 关掉 Python GIL

  • pybind11 — Seamless operability between C++11 and Python

  • Cython

  • CFFI: C Foreign Function Interface for Python. Interact with almost any C code from Python, based on C-like declarations that you can often copy-paste from header files or documentation.

  • zig cc: a Powerful Drop-In Replacement for GCC/Clang

  • wechatpy: 微信公众平台第三方 Python SDK

  • OrbStack: Fast, light, simple Docker & Linux on macOS

  • FancyWM - a dynamic tiling window manager for Windows 10/11

  • CSAPP: Computer Systems: A Programmer's Perspective

  • APUE: Advanced Programming in the UNIX® Environment

  • 提到的读书撕书的灵感来自于:李敖先生

  • 吴恩达 prompt engineering 课程:
    ChatGPT Prompt Engineering for Developers

  • Kiwi 浏览器


爱发电上赞助

展开Show Notes
_leven
_leven
2023.5.13
失踪人口回归,让捕蛇者说再次伟大!
pyo3的命名原因,化学符号。氧化铁是Fe2O3,PyO3表示生锈的Python?。。。
江无焱
江无焱
2023.5.15
下集是不是就要聊 MOJO 了
HD213361h
HD213361h
2023.5.19
这个阵容确实是过年了
icejoywoo
icejoywoo
2023.5.15
1:12:57 好像撕书的是李敖,看一本撕一本
lokfantastic
lokfantastic
2023.5.14
03:21 这个主播的声音真的是抖如筛糠……这么局促就不要强迫自己录播客了…
RyomaHan:这里稍微解释一下,这位是本期节目的嘉宾,是我们邀请来的,与节目主播并不是旧相识,而且节目录制出来后肯定会有很多人听,在录制刚开始的时候有一些紧张是正常的。
lokfantastic
lokfantastic
2023.5.13
你还知道回来!(娇嗔)
来了
WangHeng
WangHeng
2023.5.14
裁书这个好希望有出版社可以考虑下啊,哈哈哈哈。
华丽
华丽
2023.5.14
来了!
终于等到了
Fenixsin
Fenixsin
2023.5.13
来了
喻潇
喻潇
2023.5.13
讲得非常精彩,知识有用