#object #pyo3 #python

pyo3-filelike

Rust access to Python file-like objects

6 releases (3 breaking)

0.4.2 Apr 8, 2025
0.4.1 Mar 17, 2025
0.3.0 Jun 25, 2024
0.2.0 Nov 26, 2023
0.1.0 Nov 26, 2023

#75 in FFI

Download history 618/week @ 2024-12-29 652/week @ 2025-01-05 522/week @ 2025-01-12 472/week @ 2025-01-19 609/week @ 2025-01-26 1634/week @ 2025-02-02 4452/week @ 2025-02-09 3106/week @ 2025-02-16 1785/week @ 2025-02-23 4603/week @ 2025-03-02 4520/week @ 2025-03-09 3104/week @ 2025-03-16 2309/week @ 2025-03-23 1884/week @ 2025-03-30 1552/week @ 2025-04-06 924/week @ 2025-04-13

6,735 downloads per month
Used in 8 crates (via breezyshim)

Apache-2.0

14KB
287 lines

Rust compatible wrappers for file-like objects in Python

This crate provides implementations of the Write, Seek, Read and AsRawFd rust traits on top of file-like objects in PyO3.

Example

let o = pyo3::Python::with_gil(|py| {
    let io = py.import("io")?;
    io.call_method1("BytesIO", ("hello",))
})?;
let f = py3o_filelike::PyBinaryFile::from(o);

let mut buf = [0u8; 4];
f.read_exact(&mut buf)?;
assert_eq!(&buf, b"hell");

Dependencies

~2.5MB
~51K SLoC