Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Python Query

Python library heavily inspired by react-query.

Getting Started

Here is a compilation of some actions that are achievable with this library.

import asyncio

import python_query


async def function() -> None:
    await asyncio.sleep(1)
    return 2


async def main():
    query_cache = python_query.QueryCache()
    query_cache["query1"] = lambda: 1
    query_cache["query2"] = function

    assert await query_cache["query1"].fetch_async() == 1
    assert await query_cache["query2"].fetch_async() == 2

    query_cache["query1"] = lambda: 3

    assert await query_cache["query1"].fetch_async() == 3

    query_cache["parent", "child1", {"page": 1}] = lambda: 4
    query_cache["parent", "child1", {
        "page": 1, "per_page": 10}] = lambda: 5
    queries = query_cache.get_queries_not_exact("parent")
    queries2 = query_cache.get_queries_not_exact(["parent", "child1"])
    queries3 = query_cache.get_queries_not_exact(
        ["parent", "child1", {"page": 1}])

    assert len(queries) == 2
    assert len(queries2) == 2
    assert len(queries3) == 2


asyncio.run(main())

Decorators

The library also provides decorators to easily create queries.

import asyncio

import python_query

query_cache = python_query.QueryCache()


# Static keys
@QueryCache.cache(query_cache, ["key", "1"])
async def function() -> None:
    await asyncio.sleep(1)
    return 2

# Generate keys based on the arguments
@QueryCache.cache(query_cache, lambda number: ["key", "1", number])
async def function2(number : int) -> None:
    await asyncio.sleep(1)
    return number


async def main():
    # Only added to cache when called first time
    assert query_cache.get_query(["key", "1"]) is None

    assert await function() == 2
    assert query_cache.get_query(["key", "1"]) is not None
    assert await query_cache.get_query(["key", "1"]).fetch_async() == 2
    assert await function() == 2


    # Only added to cache when called first time
    assert query_cache.get_query(["key", "1", 3]) is None

    assert await function2(3) == 3
    assert query_cache.get_query(["key", "1", 2]) is None
    assert query_cache.get_query(["key", "1", 3]) is not None
    assert await query_cache.get_query(["key", "1", 3]).fetch_async() == 3
    assert await function2(3) == 3


asyncio.run(main())

Metadata

Release files for python-query 0.0.1b3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-query 0.0.1b3
File Size Uploaded
python-query-0.0.1b3.tar.gz 44.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-query 0.0.1b3
File Interpreter ABI Platform
python_query-0.0.1b3-py3-none-any.whl Python 3 none any Details

Total release size: 75.0 kB

Release files / python-query-0.0.1b3.tar.gz

Download URL python-query-0.0.1b3.tar.gz
Size 44.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a59ac8c9b41f01d4a8a2d98dfa1e5ff8177b8a888cc7fcd9729c9718d2022bbc
BLAKE2b-256 checksum
How to use checksums
a7607a804d88572435c06fbc6b1ce3211e26ccddf8913eadc6380684a6130d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8

Release files / python_query-0.0.1b3-py3-none-any.whl

Download URL python_query-0.0.1b3-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9af7fd1d236e9e4c41f51a303fd7a19d62d330910c26a89995d86091d024cc5a
BLAKE2b-256 checksum
How to use checksums
02a2fcd34c5090f65d8e48e82a540c05dd4271940c1dc5756f9b84604e6249fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.8
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page