py-linq is a little wrapper package that I wrote a few years ago for querying and transforming collections of Python objects. I found that the built-in Python querying and transforming tools were lacking. Specifically, the Python API made the code unreadable and difficult to understand. It made me long for the LINQ API’s available in .NET. So I decided to sit down and try to write it.
To get started using py-linq, you will need to install it from PyPI.
pip install py-linq
To start querying and transforming your Python collection you will need to import
from py_linq import Enumerable
Enumerable is just the access point for the py-linq API. There are 2 ways to instantiate an
my_collection = Enumerable()
my_collection = Enumerable(collection)
The collection class has to implement the
__iter__ dunder. The default constructor
Enumerable() is just
Enumerable(collection) where collection is
Enumerable itself is an iterable.
The methods encapsulated by the
Enumerable class can be either executing functions or non-executing. Executing functions will iterate over the collection when it is called. Non-executing functions will not iterate over the collections. These functions will be executed only when the collection does get iterated over.
Once you have created an
Enumerable instance, the LINQ methods will become available to you. The methods implemented at this point are: