fastapi-query-conditions


Namefastapi-query-conditions JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/jonghwanhyeon/fastapi-query-conditions
SummaryFastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets
upload_time2022-12-18 05:32:12
maintainer
docs_urlNone
authorJonghwan Hyeon
requires_python>=3.7
licenseMIT
keywords fastapi query querystring condition
VCS
bugtrack_url
requirements fastapi
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastapi-query-conditions

## Introduction
FastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets.

For example, if you send a request to `/orders?amount[gte]=1000&amount[lt]=2000`, you can use the query string as parsed conditions like this:
```json
{"gte":1000,"lt":2000}
```


## Install
```bash
> pip install fastapi-query-conditions
```

## Quick Start
```python
from typing import Dict

from fastapi import Depends, FastAPI
from fastapi_query_conditions import query_conditions

app = FastAPI()

@app.get("/items")
def query_items(amount: Dict[str, int] = Depends(query_conditions(field='amount', factory=int))):
    print(amount)
    return amount
```

Then, if you send a request to `/items?amount[gte]=1000&amount[lt]=2000`, you can check the following results.
```python
{'gte': 1000, 'lt': 2000}
```

Also, you can use various factory functions for your query parameter.
```python
from datetime import datetime
from typing import Dict

from fastapi import Depends, FastAPI
from fastapi_query_conditions import query_conditions

app = FastAPI()

@app.get("/orders")
def query_orders(time: Dict[str, int] = Depends(query_conditions(field='time', factory=datetime.fromisoformat))):
    print(time)
    return time
```

Then, if you send a request to `/orders?time[gte]=2022-10-18T12:00&time[lt]=2022-10-18T12:30`, you can check the following results.
```python
{'gte': datetime.datetime(2022, 10, 18, 12, 0), 'lt': datetime.datetime(2022, 10, 18, 12, 30)}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jonghwanhyeon/fastapi-query-conditions",
    "name": "fastapi-query-conditions",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "fastapi,query,querystring,condition",
    "author": "Jonghwan Hyeon",
    "author_email": "jonghwanhyeon93@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2d/a3/a5df0565505c5756529c6963b129c5fe9f81852ec94a18acb7f157ae6fb2/fastapi-query-conditions-1.0.2.tar.gz",
    "platform": null,
    "description": "# fastapi-query-conditions\n\n## Introduction\nFastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets.\n\nFor example, if you send a request to `/orders?amount[gte]=1000&amount[lt]=2000`, you can use the query string as parsed conditions like this:\n```json\n{\"gte\":1000,\"lt\":2000}\n```\n\n\n## Install\n```bash\n> pip install fastapi-query-conditions\n```\n\n## Quick Start\n```python\nfrom typing import Dict\n\nfrom fastapi import Depends, FastAPI\nfrom fastapi_query_conditions import query_conditions\n\napp = FastAPI()\n\n@app.get(\"/items\")\ndef query_items(amount: Dict[str, int] = Depends(query_conditions(field='amount', factory=int))):\n    print(amount)\n    return amount\n```\n\nThen, if you send a request to `/items?amount[gte]=1000&amount[lt]=2000`, you can check the following results.\n```python\n{'gte': 1000, 'lt': 2000}\n```\n\nAlso, you can use various factory functions for your query parameter.\n```python\nfrom datetime import datetime\nfrom typing import Dict\n\nfrom fastapi import Depends, FastAPI\nfrom fastapi_query_conditions import query_conditions\n\napp = FastAPI()\n\n@app.get(\"/orders\")\ndef query_orders(time: Dict[str, int] = Depends(query_conditions(field='time', factory=datetime.fromisoformat))):\n    print(time)\n    return time\n```\n\nThen, if you send a request to `/orders?time[gte]=2022-10-18T12:00&time[lt]=2022-10-18T12:30`, you can check the following results.\n```python\n{'gte': datetime.datetime(2022, 10, 18, 12, 0), 'lt': datetime.datetime(2022, 10, 18, 12, 30)}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "FastAPI-Query-Conditions is a dependency that parses a query string into conditions using operators enclosed in square brackets",
    "version": "1.0.2",
    "split_keywords": [
        "fastapi",
        "query",
        "querystring",
        "condition"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "64187061e2f87364e7ee4fa4c4fb9b59",
                "sha256": "1528bfe897d9a6c717ee355054e2577e108c91bc8846271191efce1567fa4c8a"
            },
            "downloads": -1,
            "filename": "fastapi_query_conditions-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64187061e2f87364e7ee4fa4c4fb9b59",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 3380,
            "upload_time": "2022-12-18T05:32:09",
            "upload_time_iso_8601": "2022-12-18T05:32:09.969216Z",
            "url": "https://files.pythonhosted.org/packages/f3/32/9d81266fcfa0a75a26e1963dc5b0b1eecedab0607d80596d5c42e46a4d34/fastapi_query_conditions-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "25c3b7cb1d2b107cc4c17c5725a0ddf7",
                "sha256": "d27989d60b846ab6a61816143e3228705f69a3c15dfe91831a87c740b1f91c6d"
            },
            "downloads": -1,
            "filename": "fastapi-query-conditions-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "25c3b7cb1d2b107cc4c17c5725a0ddf7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3084,
            "upload_time": "2022-12-18T05:32:12",
            "upload_time_iso_8601": "2022-12-18T05:32:12.007471Z",
            "url": "https://files.pythonhosted.org/packages/2d/a3/a5df0565505c5756529c6963b129c5fe9f81852ec94a18acb7f157ae6fb2/fastapi-query-conditions-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-18 05:32:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "jonghwanhyeon",
    "github_project": "fastapi-query-conditions",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "fastapi",
            "specs": []
        }
    ],
    "lcname": "fastapi-query-conditions"
}
        
Elapsed time: 0.03006s