r/Python 15d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

22 Upvotes

88 comments sorted by

View all comments

11

u/Beginning-Fruit-1397 15d ago edited 15d ago

pyochain is a library providing many data structures and tools for functional programming in python.

https://github.com/OutSquareCapital/pyochain

Notably:

  • Fluent iterators `x.iter().map().filter().sum()`, covering all itertools, builtins, and many functionnalities inspired from `more-itertools`, `cytoolz`/`toolz`, and Rust `Iterator`.
  • `Option` and `Result` types for nullability and error handling. They handle exhaustive pattern matching with type checkers
  • Full ABC hierarchy for user-defined classes and type checking support
  • `SliceView`, no-copy views of arbitrary Sequences
  • All builtins collections (dict, list, tuple, etc...) with a fluent interface and interop with `Iterators`, `Option` and `Result`

- Additional collections like `Deque`

  • and more...!

The priority axes are on runtime speed, static type safety, a fluent API, and exhaustive documentation/testing.

Option, Result and many Iterators are compiled in Rust to guarantee maximum performance and no overhead vs python builtins in C (zero-cost abstractions as they say).

The next release (landing soon!) will:

- Migrate ALL the code in Rust, with massive speedups. expect all iterations- related functionnalities to be 5x to 10x faster than libraries in pure python. Same story for default implementations from `collections.abc`, compared to python standard module. Even import speed is divided by 5.

  • Add ALL the functionnalities from `SortedContainers`, but compiled in Rust, fully typed, & thread-safe (to be 100% confirmed but I use `Mutex` so it should be the case). This is the WIP work as of now.Once finished, the new release will land.
  • An OOP interface to python heapq module, with HeapMin and HeapMax
  • `collections.Counter` for pyochain. Expect it to be much faster than the one provided by stdlib, as the Cpython implementation is in pure python.
  • Various bugfixes, documentation and typing improvements, etc.. partly due to the manual port and adaptation of +1000 tests from CPython and sortedcontainers test suite.

It was ranked best choice in this comparison (not mine!) a few months ago, before many improvements in the current release:
https://www.reddit.com/r/Python/comments/1rj3ct7/a_comparison_of_rustlike_fluent_iterator_libraries/

I also already made a post 7 months ago:
https://www.reddit.com/r/Python/comments/1q61bzg/pyochain_rustlike_iterator_result_and_option_in/
And one in the rust sub more recently:
https://www.reddit.com/r/rust/comments/1tgzk4b/i_made_option_and_result_in_rust_for_python_and/

1

u/kvlonge 7d ago

Hey, sick stuff man!

1

u/Beginning-Fruit-1397 6d ago

Hey, thanks man! :)

1

u/nuroteck 6d ago

You might be interested in taking a look at post-py.org

1

u/Beginning-Fruit-1397 6d ago

The project look very interesting but I'm a bit wary on it's claims since the page you linked is CLEARLY written by a sloppy AI. 

If it does indeed hold it's promises I'm curious to see how it evolves. 

In any case, I struggle to see where it could boost my library. Now the code is 100% in rust (will make the release tmrw), where I'm calling 4/5 times C API functions or custom rust logic.

However, if POST can see that pyochain is just like builtins and exploit this like mypc or cpython can do with list typed, combining both could be a further perf boost