Skip to main content

No project description provided

Project description


Try bring C# linq to python 馃巿.

The library is a demo, not for production (yet).

Compare with Others

Different between lquery and others (linq for python like asq):

**lquery try convert func (from bytecode) to SQL and query from database process.**

Compare with CSharp

For C#:

.. code-block:: cs

IQueryable<?> query = null;
var items = query.Where(z => z.Name == 's').Select(z => z.Value).ToList();

So for python:

.. code-block:: py

query: Queryable = None;
expr = query.where(z => == 's').select(z => z.value).to_list();

for in-memory iterable

.. code-block:: py

from lquery import enumerable
query: Queryable = enumerable([1, 2, 3])
# then query it

for mongodb

.. code-block:: py

from lquery.extras.mongodb import MongoDbQuery
collection = # get a collection from pymongo
query: Queryable = MongoDbQuery(collection)
# then query it

linq APIs

* ``to_memory`` - same as ``AsEnumerable()`` from C#
* ``where``
* ``select``
* ``select_many``
* ``take``
* ``skip``

read more examples from unittests.


print reduce info

Print reduce info is easy way to check what query will compile to SQL.

code example:

.. code-block:: py

>>> from lquery.extras.mongodb import MongoDbQuery
>>> mongo_query = MongoDbQuery(None)
>>> reduce_info = mongo_query\
... .where(lambda x: (x['size']['h'] == 14) & (x['size']['uom'] == 'cm'))\
... .skip(1)\
... .where(lambda x: x['size']['w'] > 15)\
... .get_reduce_info()
>>> reduce_info.print()
reduce info of:
.where(<function <lambda> at 0x0000025DBC661EA0>)
.where(<function <lambda> at 0x0000025DBE957840>)
[SQL] where(<function <lambda> at 0x0000025DBC661EA0>)
[SQL] skip(1)
[MEM] where(<function <lambda> at 0x0000025DBE957840>)

you can see the 1st ``where()`` and 1st ``skip()`` was success compile to SQL, and 2nd ``where()`` only work inside python process.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lquery, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size lquery-0.1.1-py3.6.egg (71.6 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size lquery-0.1.1.tar.gz (14.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page