lilliepy-query


Namelilliepy-query JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/websitedeb/lilliepy-query
Summaryfetching library for fetching and caching data for the Lilliepy Framework
upload_time2024-12-25 02:36:42
maintainerNone
docs_urlNone
authorSarthak Ghoshal
requires_python>=3.6
licenseMIT
keywords lilliepy lilliepy-query reactpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Lilliepy-query

this is a sub module for the lilliepy framework to be able to query and cache queries effectivly

## dependecies

* request
* time
* threading
* reactpy
* asyncio

## how to use

### Import: 

step 1:
```bash
pip install lilliepy-query
```

step 2:
```python
from lilliepy-query import Fetcher, use_query
```

### Syntax for Fetcher:
this is for the people who want to use a class, rather than a function hook

you will be using these 4 lines of code the most:

```python
from lilliepy import Fetcher

req = query.Fetcher("https://jsonplaceholder.typicode.com", refetch_interval=2) # initilizes the Fetcher class, you will now be able to start fetching and caching data, params are listed in the class comment docs
req.fetch("/todos/3") # fetches the data, since the base url is "https://jsonplaceholder.typicode.com", it will fetch from "https://jsonplaceholder.typicode.com/todos/3"
req.refetch("/todos/3") # refetches every interval stated by the Fetcher init, in this case, 2

data, err, load = req.get_state() # 3 vars are declared here: data, for the data from the fetch; error, for containing any error from preforming the fetch; and load, to indicate if the fetch is still loading or not
```

### Syntax for use_query:
this is for the people who want to have a function hook

```python
# MainPage.x.py
# the title of the page that was specified above is the file arrangement so that lilliepy-dir-router can route it correctly

from reactpy import component, html
from lilliepy-query import use_query
import httpx # if you want to use this

async def fetch_example_data(): # fetching function (pro tip: you can use the Fetcher for this part!!!)
    async with httpx.AsyncClient() as client:
        response = await client.get("https://api.example.com/data")
        response.raise_for_status()
        return response.json()


@component
def MainPage():
    query = use_query(
        query_key="example-data", # query key
        fetch_function=fetch_example_data, # query function
        enabled=True, #should it execute on mount, in this case, yes
        refetch_interval=30  # Refetch every 30 seconds
    )

    if query["is_loading"]: # if query is loading
        return html.div("Loading...")

    if query["error"]: #if query had an error
        return html.div(f"Error: {query['error']}")

    if query["data"]: #when query gets data
        return html.div(f"Data: {query['data']}")

    return html.div("No data available.") #nothing came out (shouldnt happen)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/websitedeb/lilliepy-query",
    "name": "lilliepy-query",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "lilliepy, lilliepy-query, reactpy",
    "author": "Sarthak Ghoshal",
    "author_email": "sarthak22.ghoshal@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/81/73/c64281a48d498c8bf307b86eac7f8a772534a8cb926abc22772d6cbeccfd/lilliepy_query-0.1.tar.gz",
    "platform": null,
    "description": "# Lilliepy-query\r\n\r\nthis is a sub module for the lilliepy framework to be able to query and cache queries effectivly\r\n\r\n## dependecies\r\n\r\n* request\r\n* time\r\n* threading\r\n* reactpy\r\n* asyncio\r\n\r\n## how to use\r\n\r\n### Import: \r\n\r\nstep 1:\r\n```bash\r\npip install lilliepy-query\r\n```\r\n\r\nstep 2:\r\n```python\r\nfrom lilliepy-query import Fetcher, use_query\r\n```\r\n\r\n### Syntax for Fetcher:\r\nthis is for the people who want to use a class, rather than a function hook\r\n\r\nyou will be using these 4 lines of code the most:\r\n\r\n```python\r\nfrom lilliepy import Fetcher\r\n\r\nreq = query.Fetcher(\"https://jsonplaceholder.typicode.com\", refetch_interval=2) # initilizes the Fetcher class, you will now be able to start fetching and caching data, params are listed in the class comment docs\r\nreq.fetch(\"/todos/3\") # fetches the data, since the base url is \"https://jsonplaceholder.typicode.com\", it will fetch from \"https://jsonplaceholder.typicode.com/todos/3\"\r\nreq.refetch(\"/todos/3\") # refetches every interval stated by the Fetcher init, in this case, 2\r\n\r\ndata, err, load = req.get_state() # 3 vars are declared here: data, for the data from the fetch; error, for containing any error from preforming the fetch; and load, to indicate if the fetch is still loading or not\r\n```\r\n\r\n### Syntax for use_query:\r\nthis is for the people who want to have a function hook\r\n\r\n```python\r\n# MainPage.x.py\r\n# the title of the page that was specified above is the file arrangement so that lilliepy-dir-router can route it correctly\r\n\r\nfrom reactpy import component, html\r\nfrom lilliepy-query import use_query\r\nimport httpx # if you want to use this\r\n\r\nasync def fetch_example_data(): # fetching function (pro tip: you can use the Fetcher for this part!!!)\r\n    async with httpx.AsyncClient() as client:\r\n        response = await client.get(\"https://api.example.com/data\")\r\n        response.raise_for_status()\r\n        return response.json()\r\n\r\n\r\n@component\r\ndef MainPage():\r\n    query = use_query(\r\n        query_key=\"example-data\", # query key\r\n        fetch_function=fetch_example_data, # query function\r\n        enabled=True, #should it execute on mount, in this case, yes\r\n        refetch_interval=30  # Refetch every 30 seconds\r\n    )\r\n\r\n    if query[\"is_loading\"]: # if query is loading\r\n        return html.div(\"Loading...\")\r\n\r\n    if query[\"error\"]: #if query had an error\r\n        return html.div(f\"Error: {query['error']}\")\r\n\r\n    if query[\"data\"]: #when query gets data\r\n        return html.div(f\"Data: {query['data']}\")\r\n\r\n    return html.div(\"No data available.\") #nothing came out (shouldnt happen)\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "fetching library for fetching and caching data for the Lilliepy Framework",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/websitedeb/lilliepy-query"
    },
    "split_keywords": [
        "lilliepy",
        " lilliepy-query",
        " reactpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b777e83a1b7c5ef0e3637ac1ec75af182898933091d87ee535d5209ef663b7c5",
                "md5": "d689706a86603b0cd9489c8deeeb4814",
                "sha256": "59f94debd830c4f7e1a6ce2a85622f16feb9e59f7e1cc893203e9de44ef9ae38"
            },
            "downloads": -1,
            "filename": "lilliepy_query-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d689706a86603b0cd9489c8deeeb4814",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4764,
            "upload_time": "2024-12-25T02:36:41",
            "upload_time_iso_8601": "2024-12-25T02:36:41.262120Z",
            "url": "https://files.pythonhosted.org/packages/b7/77/e83a1b7c5ef0e3637ac1ec75af182898933091d87ee535d5209ef663b7c5/lilliepy_query-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8173c64281a48d498c8bf307b86eac7f8a772534a8cb926abc22772d6cbeccfd",
                "md5": "f74a1e0e8d6e596f2eb035c1661c6384",
                "sha256": "e803f9fc348d1106b2ca783b8d6315da35952eb0f015dbcae8ba663c0c244cda"
            },
            "downloads": -1,
            "filename": "lilliepy_query-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f74a1e0e8d6e596f2eb035c1661c6384",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4507,
            "upload_time": "2024-12-25T02:36:42",
            "upload_time_iso_8601": "2024-12-25T02:36:42.460185Z",
            "url": "https://files.pythonhosted.org/packages/81/73/c64281a48d498c8bf307b86eac7f8a772534a8cb926abc22772d6cbeccfd/lilliepy_query-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-25 02:36:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "websitedeb",
    "github_project": "lilliepy-query",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "lilliepy-query"
}
        
Elapsed time: 0.45693s