← 输入框|github.com|刷新
Skip to content

[RFC] Consider a pure python stdlib #5492

Open

Description

@adsharma

Summary

I noticed that you have a stdlib implementation in rust. Not sure how complete it is. But there are probably more projects that are trying to innovate in the python ecosystem without using C-API and GIL.

Wouldn't it be better if these projects collaborated and produced one stdlib implementation that is usable by multiple projects?

Detailed Explanation

https://github.com/adsharma/py-stdlib where I'm working on implementing the top 100 most used functions.

Subsequently this can be transpiled to many languages, each using the language specific FFI. But the core library remains in a restricted subset of python that could be transpiled.

Mojo is likely considering doing this as well (but in mojo, not statically typed python).

Drawbacks, Rationale, and Alternatives

Breaks compatibility. Not sure if pypy will consider it.

Unresolved Questions

Some unresolved questions in the issue tracker of the project linked.

Activity

  1. youknowone commented on Jan 28, 2025

    @youknowone
    Member

    Thank you for suggestion. We not only borrowed python libraries from CPython, but also from other pure python libraries pypy(mostly rewritten in rpython), ouroboros(discontinued) and brython . This library also can be one of the candidate.

  2. adsharma commented on Jan 28, 2025

    @adsharma
    Author

    Thank you for that pointer. I guessed someone must've tried to do this before. I couldn't discover it via searches:

    https://github.com/beeware/ouroboros

    A few differences vs other efforts:

    • Focus on transpiling the pure python implementation (as opposed to using it as-is or via a JIT)
    • Not concerned about 100% backward compatibility (we're breaking C-API already)
    • Target the most used surface of the python stdlib API (assuming some skewed distribution 80-20 or 90-10)
  3. arihant2math commented on Jan 28, 2025

    @arihant2math
    Contributor

    I think trying to stick to the cpython stdlib is good if we want things the ctypes. However this might be a good stopgap solution for certain unimplemented functions. The problem I see is most of the unimplemented functions lie in obscure locations, which this wouldn't cover.

  4. adsharma commented on Jan 28, 2025

    @adsharma
    Author

    I see ctypes/cffi as a way to get to some native functionality. A transpiler can be taught to convert calls to python cffi to rust ffi.

    If your goal is to have python stdlib implemented in rust one day, this might be better aligned with that direction. But I couldn't tell if that's a goal.

    Yes - this wouldn't help you with library coverage, since it's far less complete than some of the other implementations.

  5. youknowone commented on Feb 1, 2025

    @youknowone
    Member

    I believe having pure python backup is always a good idea. It has 2 good points.

    First, it can be a step-by-step procedure. For example, CPython also uses _pydatetime.py and both-implemented functools. we have both functools.py and functools.rs. CPython replaces more implementation with C, but we only replace reduce.

    Second, it is binary size friendly in a few scenario. Unlike Rust implementation, pure python stdlib can be selected on runtime. Many RustPython users are looking for using it as embedded python. Using pure python will drop the performance but also decrease the size of binary - Because it can be provided from environment on demand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest for comments

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions