# Python advanced query table example

**URL:** <https://forums.losant.com/t/python-advanced-query-table-example/5293>\
**Category:** Help\
**Tags:** python\
**Created:** [October 12, 2023, 10:27am UTC](https://forums.losant.com/t/python-advanced-query-table-example/5293 "2023-10-12T10:27:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [October 12, 2023, 10:27am UTC](https://forums.losant.com/t/python-advanced-query-table-example/5293/1 "2023-10-12T10:27:54Z")

</div>

There are missing links in this page:

> <https://github.com/Losant/losant-rest-python/blob/master/docs/dataTableRows.md#get>

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/55afe04f8860b43c2924b7ac462e5724d79bb563.png)

Can you provide a real example with the AdvancedQuery object?  
The link goes into a massive raw file.

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [October 12, 2023, 2:34pm UTC](https://forums.losant.com/t/python-advanced-query-table-example/5293/2 "2023-10-12T14:34:57Z")

</div>

When I have to construct advanced queries for use in the API, I like to start in the Losant UI, construct a similar query, and then copy that out of my browser’s console. Go to the Network tab, find the request you are interested in, and pull the query out of the body.

As for this particular example, the `query` argument for `data_table_rows.query` expects a JSON object in [Losant’s advanced query syntax](https://docs.losant.com/references/advanced-queries/).

So for example, say I wanted to return all data table rows where the “number” column (which is of the `Number` type) has a value greater than or equal to 4, OR less than or equal to 2. Using the Python REST client, that would look like …

```python
from losantrest import Client
client = Client(auth_token=my_auth_token)
result = client.data_table_rows.query(applicationId=my_application_id, dataTableId=my_data_table_id, query={
  "$or": [
    { "number": {"$gte": 4} },
    { "number": {"$lte": 2} }
  ]})
print(result)
```

---

<div class="post-metadata">

**Author:** ![Paolo\_Proxy](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@Paolo\_Proxy](https://forums.losant.com/u/Paolo_Proxy)\
**Post date:** [October 16, 2023, 9:48am UTC](https://forums.losant.com/t/python-advanced-query-table-example/5293/3 "2023-10-16T09:48:25Z")

</div>

It makes sense now, I was expecting a Pythonic object, instead is just the JSON syntax of the query.  
Okay this makes sense now!
