grafliq


Namegrafliq JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/mononobi/grafliq
SummaryA simple and pythonic way to query GraphQL endpoints without having to do any string manipulation.
upload_time2024-08-09 23:11:35
maintainermono
docs_urlNone
authormono
requires_python>=3.6
licenseBSD-3-Clause
keywords graphql python grafliq graphql-query pythonic graphql-client graphql-tool pythonic-graphql-tool graphql-for-humans pythonic-graphql graphql-query-builder graphql-queries graphql-query-generator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Grafliq
A simple and pythonic way to query GraphQL endpoints without having to do 
any string manipulation.

Grafliq is a GraphQL client that provides a convenient way to handle GraphQL queries. 
Instead of building your query by manipulating and concatenating strings, you build 
your queries using function calls, eliminating all the complications and problems 
associated with string manipulation, and making maintenance an easy task.

## Important note
Grafliq only supports the `query` operation of GraphQL, there is no support 
for `mutations` and `subscriptions` and there will be none in the foreseeable future.

## Installing

**Install using pip**:

**`pip install grafliq`**

## Example using function calls as GraphQL operations (recommended)

Let's say we want to have a GraphQL query with the following structure:

```
{
  category(name: "household-appliances") {
    electronics {
      gaming_consoles(
        fromReleaseDate: "2000-01-01"
        fromPrice: "150"
        discontinued: false
        colors: [BLACK, WHITE, RED]
      ) {
        brand
        name
        color
        discontinued
        release_date
        price(currency: "euro")
        model {
          name
          version
        }
        customer_rating(fromRatingDate: "2002-10-01") {
          count
          rates {
            average(decimalCount: 2)
            highest
            lowest
          }
        }
      }
    }
  }
}
```

We can generate the above query using the following Python code:

```python
from datetime import date
from grafliq.builder import GraphQL
from grafliq.query import NestedField, Quote, NoQuote, CustomizableField

query = GraphQL(
    endpoint='http://127.0.0.1:8080/graphql-api'
).category(
    name='household-appliances'
).electronics(
).gaming_consoles(
    'brand', 'name', 'color', 'discontinued', 'release_date',
    CustomizableField('price', currency="euro"),
    NestedField('model',
                'name', 'version'),
    NestedField('customer_rating',
                'count',
                NestedField('rates',
                            CustomizableField('average', decimalCount=2),
                            'highest', 'lowest'),
                fromRatingDate=date(2002, 10, 1)),
    fromReleaseDate=date(2000, 1, 1),
    fromPrice=Quote(150),
    discontinued=False,
    colors=NoQuote(['BLACK', 'WHITE', 'RED'])
)

"""
To get the query as a string, you can either do this:
"""

query_string1 = str(query)

"""
Or you can call `.generate()` on the query object:
"""

query_string2 = query.generate()

"""
If you pass the `endpoint` to the `GraphQL` initializer, you can 
call `.execute()` directly on the query object to call the remote API and get the result:
"""

result = query.execute()

"""
Note that if you have not passed the `endpoint` to the 
`GraphQL` initializer, by calling the `.execute()` function, an error will be raised.
"""
```

As shown in the example above, any operation available in the remote GraphQL API 
will be available as a function on the `GraphQL` object.

## Example using generic query

If you want to dynamically generate GraphQL queries 
(.ex in an automated script, from user input, ...), you can do this with 
the following example, which will generate exactly the same GraphQL query:

```python
from datetime import date
from grafliq.builder import GraphQL
from grafliq.query import NestedField, Quote, NoQuote, CustomizableField

query = GraphQL(
    endpoint='http://127.0.0.1:8080/graphql-api'
).query(
    'category',
    name='household-appliances'
).query(
    'electronics'
).query(
    'gaming_consoles',
    'brand', 'name', 'color', 'discontinued', 'release_date',
    CustomizableField('price', currency="euro"),
    NestedField('model',
                'name', 'version'),
    NestedField('customer_rating',
                'count',
                NestedField('rates',
                            CustomizableField('average', decimalCount=2),
                            'highest', 'lowest'),
                fromRatingDate=date(2002, 10, 1)),
    fromReleaseDate=date(2000, 1, 1),
    fromPrice=Quote(150),
    discontinued=False,
    colors=NoQuote(['BLACK', 'WHITE', 'RED'])
)
```

## Contribute to Grafliq development

I appreciate any kind of contribution to the development of Grafliq, 
especially to add support for mutations and subscriptions.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mononobi/grafliq",
    "name": "grafliq",
    "maintainer": "mono",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "mononobi@gmail.com",
    "keywords": "graphql python grafliq graphql-query pythonic graphql-client graphql-tool pythonic-graphql-tool graphql-for-humans pythonic-graphql graphql-query-builder graphql-queries graphql-query-generator",
    "author": "mono",
    "author_email": "mononobi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/06/7e/93c20aeb3c75c193af0a23f143b5d8ed96f397883d09cf7c6093cb3f872e/grafliq-0.1.0.tar.gz",
    "platform": null,
    "description": "# Grafliq\nA simple and pythonic way to query GraphQL endpoints without having to do \nany string manipulation.\n\nGrafliq is a GraphQL client that provides a convenient way to handle GraphQL queries. \nInstead of building your query by manipulating and concatenating strings, you build \nyour queries using function calls, eliminating all the complications and problems \nassociated with string manipulation, and making maintenance an easy task.\n\n## Important note\nGrafliq only supports the `query` operation of GraphQL, there is no support \nfor `mutations` and `subscriptions` and there will be none in the foreseeable future.\n\n## Installing\n\n**Install using pip**:\n\n**`pip install grafliq`**\n\n## Example using function calls as GraphQL operations (recommended)\n\nLet's say we want to have a GraphQL query with the following structure:\n\n```\n{\n  category(name: \"household-appliances\") {\n    electronics {\n      gaming_consoles(\n        fromReleaseDate: \"2000-01-01\"\n        fromPrice: \"150\"\n        discontinued: false\n        colors: [BLACK, WHITE, RED]\n      ) {\n        brand\n        name\n        color\n        discontinued\n        release_date\n        price(currency: \"euro\")\n        model {\n          name\n          version\n        }\n        customer_rating(fromRatingDate: \"2002-10-01\") {\n          count\n          rates {\n            average(decimalCount: 2)\n            highest\n            lowest\n          }\n        }\n      }\n    }\n  }\n}\n```\n\nWe can generate the above query using the following Python code:\n\n```python\nfrom datetime import date\nfrom grafliq.builder import GraphQL\nfrom grafliq.query import NestedField, Quote, NoQuote, CustomizableField\n\nquery = GraphQL(\n    endpoint='http://127.0.0.1:8080/graphql-api'\n).category(\n    name='household-appliances'\n).electronics(\n).gaming_consoles(\n    'brand', 'name', 'color', 'discontinued', 'release_date',\n    CustomizableField('price', currency=\"euro\"),\n    NestedField('model',\n                'name', 'version'),\n    NestedField('customer_rating',\n                'count',\n                NestedField('rates',\n                            CustomizableField('average', decimalCount=2),\n                            'highest', 'lowest'),\n                fromRatingDate=date(2002, 10, 1)),\n    fromReleaseDate=date(2000, 1, 1),\n    fromPrice=Quote(150),\n    discontinued=False,\n    colors=NoQuote(['BLACK', 'WHITE', 'RED'])\n)\n\n\"\"\"\nTo get the query as a string, you can either do this:\n\"\"\"\n\nquery_string1 = str(query)\n\n\"\"\"\nOr you can call `.generate()` on the query object:\n\"\"\"\n\nquery_string2 = query.generate()\n\n\"\"\"\nIf you pass the `endpoint` to the `GraphQL` initializer, you can \ncall `.execute()` directly on the query object to call the remote API and get the result:\n\"\"\"\n\nresult = query.execute()\n\n\"\"\"\nNote that if you have not passed the `endpoint` to the \n`GraphQL` initializer, by calling the `.execute()` function, an error will be raised.\n\"\"\"\n```\n\nAs shown in the example above, any operation available in the remote GraphQL API \nwill be available as a function on the `GraphQL` object.\n\n## Example using generic query\n\nIf you want to dynamically generate GraphQL queries \n(.ex in an automated script, from user input, ...), you can do this with \nthe following example, which will generate exactly the same GraphQL query:\n\n```python\nfrom datetime import date\nfrom grafliq.builder import GraphQL\nfrom grafliq.query import NestedField, Quote, NoQuote, CustomizableField\n\nquery = GraphQL(\n    endpoint='http://127.0.0.1:8080/graphql-api'\n).query(\n    'category',\n    name='household-appliances'\n).query(\n    'electronics'\n).query(\n    'gaming_consoles',\n    'brand', 'name', 'color', 'discontinued', 'release_date',\n    CustomizableField('price', currency=\"euro\"),\n    NestedField('model',\n                'name', 'version'),\n    NestedField('customer_rating',\n                'count',\n                NestedField('rates',\n                            CustomizableField('average', decimalCount=2),\n                            'highest', 'lowest'),\n                fromRatingDate=date(2002, 10, 1)),\n    fromReleaseDate=date(2000, 1, 1),\n    fromPrice=Quote(150),\n    discontinued=False,\n    colors=NoQuote(['BLACK', 'WHITE', 'RED'])\n)\n```\n\n## Contribute to Grafliq development\n\nI appreciate any kind of contribution to the development of Grafliq, \nespecially to add support for mutations and subscriptions.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A simple and pythonic way to query GraphQL endpoints without having to do any string manipulation.",
    "version": "0.1.0",
    "project_urls": {
        "Code": "https://github.com/mononobi/grafliq",
        "Homepage": "https://github.com/mononobi/grafliq",
        "Issue tracker": "https://github.com/mononobi/grafliq/issues"
    },
    "split_keywords": [
        "graphql",
        "python",
        "grafliq",
        "graphql-query",
        "pythonic",
        "graphql-client",
        "graphql-tool",
        "pythonic-graphql-tool",
        "graphql-for-humans",
        "pythonic-graphql",
        "graphql-query-builder",
        "graphql-queries",
        "graphql-query-generator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36761ce252fa6bd256186097477a7d8a687025d37ec180d88d6894107cd5c7ad",
                "md5": "faff045e461210e10e0a8904870e7536",
                "sha256": "3a823ec30e5d1816a31a7c2fb7c4a33e740f6c173c24d9005338acdc2c88ba60"
            },
            "downloads": -1,
            "filename": "grafliq-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "faff045e461210e10e0a8904870e7536",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 9181,
            "upload_time": "2024-08-09T23:11:33",
            "upload_time_iso_8601": "2024-08-09T23:11:33.432429Z",
            "url": "https://files.pythonhosted.org/packages/36/76/1ce252fa6bd256186097477a7d8a687025d37ec180d88d6894107cd5c7ad/grafliq-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "067e93c20aeb3c75c193af0a23f143b5d8ed96f397883d09cf7c6093cb3f872e",
                "md5": "f7c88368c48dcb75b22a620b77afc1bb",
                "sha256": "3a2e8b332f44df5786e010c0ece31bbf1b81aba020756531b839f7ae5e1e0ea1"
            },
            "downloads": -1,
            "filename": "grafliq-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f7c88368c48dcb75b22a620b77afc1bb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 10549,
            "upload_time": "2024-08-09T23:11:35",
            "upload_time_iso_8601": "2024-08-09T23:11:35.342275Z",
            "url": "https://files.pythonhosted.org/packages/06/7e/93c20aeb3c75c193af0a23f143b5d8ed96f397883d09cf7c6093cb3f872e/grafliq-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-09 23:11:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mononobi",
    "github_project": "grafliq",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "grafliq"
}
        
Elapsed time: 0.32101s