Skip to main content

fetching library for fetching and caching data for the Lilliepy Framework

Project description

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:

pip install lilliepy-query

step 2:

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:

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

# 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)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

lilliepy_query-0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lilliepy_query-0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file lilliepy_query-0.1.tar.gz.

File metadata

  • Download URL: lilliepy_query-0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for lilliepy_query-0.1.tar.gz
Algorithm Hash digest
SHA256 e803f9fc348d1106b2ca783b8d6315da35952eb0f015dbcae8ba663c0c244cda
MD5 f74a1e0e8d6e596f2eb035c1661c6384
BLAKE2b-256 8173c64281a48d498c8bf307b86eac7f8a772534a8cb926abc22772d6cbeccfd

See more details on using hashes here.

File details

Details for the file lilliepy_query-0.1-py3-none-any.whl.

File metadata

  • Download URL: lilliepy_query-0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for lilliepy_query-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59f94debd830c4f7e1a6ce2a85622f16feb9e59f7e1cc893203e9de44ef9ae38
MD5 d689706a86603b0cd9489c8deeeb4814
BLAKE2b-256 b777e83a1b7c5ef0e3637ac1ec75af182898933091d87ee535d5209ef663b7c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page