# ql (in development)
Graphql client library, wrapped around pydantic classes for typing validation,
provide simple, safe and dynamic way to query data from a graphql api.
using pydantic for creating python objects from rest api is common, it is easy and
it has type validation, so why not do that also for graphql apis?
features:
* python objects to valid graphql string
* http send and recv information
* scalar http responses
## Query examples
#### simple query
> ```py
> import ql
> from pydantic import BaseModel
>
>
> @ql.model
> class Point(BaseModel):
> x: int
> y: int
>
>
> q = ql.query(
> (Point, (
> ql._(Point).x,
> ql._(Point).y
> ))
> )
> print(q)
> ```
> ---
> ```
> query{Point{x,y}}
> ```
#### different query names then what defined
> ```py
> import ql
> from pydantic import BaseModel, Field
>
>
> @ql.model(query_name="Person")
> class Adult(BaseModel):
> name: Annotation[str, ql.metadata(query_name="first_name")]
>
> q = ql.query((Adult,(ql._(Adult).name,))
> print(q)
> ```
> ---
> ```
> query{Person{first_name}}
> ```
#### smart implements + nested query + inline fragment
> ```py
> import ql
> from pydantic import BaseModel
>
> @ql.model
> class Human(BaseModel):
> first_name: str
> last_name: str
>
> @ql.model
> class Female(Human):
> pregnant: bool
>
> @ql.model
> class Male(Human):
> pass
>
> print(ql.implements(Human)) # what does `Human` implement
> q = ql.query(
> (Human, (
> ql._(Human).first_name,
> (ql.on(Female), (
> ql._(Female).pregnant,
> ))
> ))
> )
> print(q)
> ```
> ---
> ```
> frozenset({<class '__main__.Human'>})
> query{Human{first_name,...on Female{pregnant,__typename},__typename}}
> ```
#### query with http
> ```py
> import ql
> import requests
> from pydantic import BaseModel
>
> ql.http.set_request_func(lambda q: requests.get(...).json())
>
> # define models ...
>
> response = ql.query_response(
> (Point, (
> ql._(Point).x,
> ql._(Point).y
> ))
> )
> print(response)
> ```
> ---
> ```
> {"data": {"point": "x": 50, "y": -50}}
> ```
#### query and scalar response
> ```py
> import ql
> import requests
> from pydantic import BaseModel
>
> ql.http.set_request_func(lambda q: requests.get(...).json())
>
> @ql.model
> class Point(BaseModel):
> x: int
> y: int
>
> scalared = ql.query_response_scalar(
> (Point, (
> ql._(Point).x,
> ql._(Point).y
> ))
> )
> print(scalared)
> ```
> ---
> ```
> {"point": Point(x=50, y=-50)}
> ```
Raw data
{
"_id": null,
"home_page": "https://github.com/dsal3389/ql",
"name": "dsal-graph-ql",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "graphql, pydantic, library",
"author": "daniel sonbolian",
"author_email": "dsal3389@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/82/90/da1347e6c3163138b0cb5ee7b80aa53db0d67feaa5fef3a2a1320e755c24/dsal_graph_ql-0.1.1a0.tar.gz",
"platform": null,
"description": "# ql (in development)\nGraphql client library, wrapped around pydantic classes for typing validation,\nprovide simple, safe and dynamic way to query data from a graphql api.\n\n\nusing pydantic for creating python objects from rest api is common, it is easy and \nit has type validation, so why not do that also for graphql apis?\n\nfeatures:\n * python objects to valid graphql string\n * http send and recv information\n * scalar http responses\n\n## Query examples\n#### simple query\n> ```py\n> import ql\n> from pydantic import BaseModel\n> \n> \n> @ql.model\n> class Point(BaseModel):\n> x: int\n> y: int\n> \n> \n> q = ql.query(\n> (Point, (\n> ql._(Point).x,\n> ql._(Point).y\n> ))\n> )\n> print(q)\n> ```\n> ---\n> ```\n> query{Point{x,y}}\n> ```\n\n#### different query names then what defined\n> ```py\n> import ql\n> from pydantic import BaseModel, Field\n> \n> \n> @ql.model(query_name=\"Person\")\n> class Adult(BaseModel):\n> name: Annotation[str, ql.metadata(query_name=\"first_name\")]\n>\n> q = ql.query((Adult,(ql._(Adult).name,))\n> print(q)\n> ```\n> ---\n> ```\n> query{Person{first_name}}\n> ```\n\n#### smart implements + nested query + inline fragment\n> ```py\n> import ql\n> from pydantic import BaseModel\n>\n> @ql.model\n> class Human(BaseModel):\n> first_name: str\n> last_name: str\n>\n> @ql.model\n> class Female(Human):\n> pregnant: bool\n>\n> @ql.model\n> class Male(Human):\n> pass\n>\n> print(ql.implements(Human)) # what does `Human` implement\n> q = ql.query(\n> (Human, (\n> ql._(Human).first_name,\n> (ql.on(Female), (\n> ql._(Female).pregnant,\n> ))\n> ))\n> )\n> print(q)\n> ```\n> ---\n> ```\n> frozenset({<class '__main__.Human'>})\n> query{Human{first_name,...on Female{pregnant,__typename},__typename}}\n> ```\n\n#### query with http\n> ```py\n> import ql\n> import requests\n> from pydantic import BaseModel\n>\n> ql.http.set_request_func(lambda q: requests.get(...).json())\n>\n> # define models ...\n>\n> response = ql.query_response(\n> (Point, (\n> ql._(Point).x,\n> ql._(Point).y\n> ))\n> )\n> print(response)\n> ```\n> ---\n> ```\n> {\"data\": {\"point\": \"x\": 50, \"y\": -50}}\n> ```\n\n#### query and scalar response\n> ```py\n> import ql\n> import requests\n> from pydantic import BaseModel\n>\n> ql.http.set_request_func(lambda q: requests.get(...).json())\n>\n> @ql.model\n> class Point(BaseModel):\n> x: int\n> y: int\n>\n> scalared = ql.query_response_scalar(\n> (Point, (\n> ql._(Point).x,\n> ql._(Point).y\n> ))\n> )\n> print(scalared)\n> ```\n> ---\n> ```\n> {\"point\": Point(x=50, y=-50)}\n> ```\n",
"bugtrack_url": null,
"license": null,
"summary": "non intrusive python graphql client library wrapped around pydantic",
"version": "0.1.1a0",
"project_urls": {
"Homepage": "https://github.com/dsal3389/ql",
"Repository": "https://github.com/dsal3389/ql"
},
"split_keywords": [
"graphql",
" pydantic",
" library"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "55deb5987cc0c48ab3ff99ed27c21b16e5dbf4925b93d4cd242f0406bbc086e3",
"md5": "513f8aec7898afb667ff8bb654e2d1ee",
"sha256": "53da201339594a3f4195eb47ac125030e3833d64ec5d6997e7dddde6ddd22af2"
},
"downloads": -1,
"filename": "dsal_graph_ql-0.1.1a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "513f8aec7898afb667ff8bb654e2d1ee",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 1927,
"upload_time": "2024-08-09T16:44:17",
"upload_time_iso_8601": "2024-08-09T16:44:17.123802Z",
"url": "https://files.pythonhosted.org/packages/55/de/b5987cc0c48ab3ff99ed27c21b16e5dbf4925b93d4cd242f0406bbc086e3/dsal_graph_ql-0.1.1a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8290da1347e6c3163138b0cb5ee7b80aa53db0d67feaa5fef3a2a1320e755c24",
"md5": "7124d414ea9c07d8fd85a5a99834927f",
"sha256": "96ca7e710305bf9e34ce53a433d60a0bd2013252c1522925a8ea575064ab925c"
},
"downloads": -1,
"filename": "dsal_graph_ql-0.1.1a0.tar.gz",
"has_sig": false,
"md5_digest": "7124d414ea9c07d8fd85a5a99834927f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 1864,
"upload_time": "2024-08-09T16:44:18",
"upload_time_iso_8601": "2024-08-09T16:44:18.288132Z",
"url": "https://files.pythonhosted.org/packages/82/90/da1347e6c3163138b0cb5ee7b80aa53db0d67feaa5fef3a2a1320e755c24/dsal_graph_ql-0.1.1a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-09 16:44:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dsal3389",
"github_project": "ql",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "dsal-graph-ql"
}