py2graphql


Namepy2graphql JSON
Version 0.19.0 PyPI version JSON
download
home_pagehttps://github.com/willemt/py2graphql
SummaryPythonic GraphQL Client
upload_time2025-02-09 21:42:45
maintainerNone
docs_urlNone
authorWillem Thiart
requires_python<4.0,>=3.7
licenseMIT
keywords graphql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            py2graphql (Python to GraphQL)
##############################

|pypi|

1. GraphQL
2. Django queryset love
3. ``__getattr__`` abuse
4. ???
5. Profit!!!


What
----
py2graphql is a Python GraphQL client that makes GraphQL feel better to use. It almost feels like you're using Django's ORM.


Installation
------------
.. code-block:: bash
   :class: ignore

   pip install py2graphql


Example
-------

This Python equates to the following GraphQL.

.. code-block:: python
   :class: ignore

   from py2graphql import Query

   Query().repository(owner='juliuscaeser', name='rome').pullRequest(number=2).values('title', 'url').commits(last=250).edges.node.commit.values('id', 'message', 'messageBody')

.. code-block:: graphql
   :class: ignore

   query {
     repository(owner: "juliuscaeser", name: "rome") {
       pullRequest(number: 2) {
         title
         url
         commits(last: 250) {
           edges {
             node {
               commit {
                 id
                 message
                 messageBody
               }
             }
           }
         }
       }
     }
   }

You can even use the library to do the HTTP requests:

.. code-block:: python
   :class: ignore

   from py2graphql import Client

   headers = {
       'Authorization': 'token MY_TOKEN',
   }
   Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()

It also supports Mutations:

.. code-block:: python
   :class: ignore

   from py2graphql import Client, Query

   headers = {
       'Authorization': 'token MY_TOKEN',
   }
   client = Client(url=THE_URL, headers=headers)
   mutation = Query(name='mutation', client=client)


And multiple queries in a single request:

.. code-block:: python
   :class: ignore

   from py2graphql import Client, Query

   headers = {
       'Authorization': 'token MY_TOKEN',
   }
   query = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome')
   query.pullRequest(number=2).values('title', 'url')
   query.releases(first=10).edges.node.values('name')
   query.get_graphql()

.. code-block:: graphql
   :class: ignore

   query {
     repository(owner: "juliuscaeser", name: "rome") {
        pullRequest(number: 2) {
          title
          url
        }
        releases(first: 10) {
          edges {
            node {
              name
            }
          }
        }
      }
   }

As well as GraphQL errors:

.. code-block:: python
   :class: ignore

   from py2graphql import Client, Query

   headers = {
       'Authorization': 'token MY_TOKEN',
   }
   result = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()
   result._errors
   [{'message': "Field 'repository' is missing required arguments: name", 'locations': [{'line': 7, 'column': 3}]}]


.. |pypi| image:: https://img.shields.io/pypi/v/py2graphql.svg?style=flat
   :target: https://pypi.python.org/pypi/py2graphql

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/willemt/py2graphql",
    "name": "py2graphql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "graphql",
    "author": "Willem Thiart",
    "author_email": "himself@willemthiart.com",
    "download_url": "https://files.pythonhosted.org/packages/29/40/20161ee5ab2856994dd38a6ebd5bc122abdc17eca57dd3454c8d875c5d43/py2graphql-0.19.0.tar.gz",
    "platform": null,
    "description": "py2graphql (Python to GraphQL)\n##############################\n\n|pypi|\n\n1. GraphQL\n2. Django queryset love\n3. ``__getattr__`` abuse\n4. ???\n5. Profit!!!\n\n\nWhat\n----\npy2graphql is a Python GraphQL client that makes GraphQL feel better to use. It almost feels like you're using Django's ORM.\n\n\nInstallation\n------------\n.. code-block:: bash\n   :class: ignore\n\n   pip install py2graphql\n\n\nExample\n-------\n\nThis Python equates to the following GraphQL.\n\n.. code-block:: python\n   :class: ignore\n\n   from py2graphql import Query\n\n   Query().repository(owner='juliuscaeser', name='rome').pullRequest(number=2).values('title', 'url').commits(last=250).edges.node.commit.values('id', 'message', 'messageBody')\n\n.. code-block:: graphql\n   :class: ignore\n\n   query {\n     repository(owner: \"juliuscaeser\", name: \"rome\") {\n       pullRequest(number: 2) {\n         title\n         url\n         commits(last: 250) {\n           edges {\n             node {\n               commit {\n                 id\n                 message\n                 messageBody\n               }\n             }\n           }\n         }\n       }\n     }\n   }\n\nYou can even use the library to do the HTTP requests:\n\n.. code-block:: python\n   :class: ignore\n\n   from py2graphql import Client\n\n   headers = {\n       'Authorization': 'token MY_TOKEN',\n   }\n   Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()\n\nIt also supports Mutations:\n\n.. code-block:: python\n   :class: ignore\n\n   from py2graphql import Client, Query\n\n   headers = {\n       'Authorization': 'token MY_TOKEN',\n   }\n   client = Client(url=THE_URL, headers=headers)\n   mutation = Query(name='mutation', client=client)\n\n\nAnd multiple queries in a single request:\n\n.. code-block:: python\n   :class: ignore\n\n   from py2graphql import Client, Query\n\n   headers = {\n       'Authorization': 'token MY_TOKEN',\n   }\n   query = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome')\n   query.pullRequest(number=2).values('title', 'url')\n   query.releases(first=10).edges.node.values('name')\n   query.get_graphql()\n\n.. code-block:: graphql\n   :class: ignore\n\n   query {\n     repository(owner: \"juliuscaeser\", name: \"rome\") {\n        pullRequest(number: 2) {\n          title\n          url\n        }\n        releases(first: 10) {\n          edges {\n            node {\n              name\n            }\n          }\n        }\n      }\n   }\n\nAs well as GraphQL errors:\n\n.. code-block:: python\n   :class: ignore\n\n   from py2graphql import Client, Query\n\n   headers = {\n       'Authorization': 'token MY_TOKEN',\n   }\n   result = Client(url=THE_URL, headers=headers).query().repository(owner='juliuscaeser', name='rome').fetch()\n   result._errors\n   [{'message': \"Field 'repository' is missing required arguments: name\", 'locations': [{'line': 7, 'column': 3}]}]\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/py2graphql.svg?style=flat\n   :target: https://pypi.python.org/pypi/py2graphql\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pythonic GraphQL Client",
    "version": "0.19.0",
    "project_urls": {
        "Homepage": "https://github.com/willemt/py2graphql",
        "Repository": "https://github.com/willemt/py2graphql"
    },
    "split_keywords": [
        "graphql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e14e13d212b4f2ab630b6978fdd58440ff7252e33f4e918fb0910f016e7db135",
                "md5": "f0392490e06201bbb16a79b8c124b62d",
                "sha256": "4dc159832b3ad52c753f9f7c4df297244ec148ac3c00148ae4b5d86264b2a404"
            },
            "downloads": -1,
            "filename": "py2graphql-0.19.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0392490e06201bbb16a79b8c124b62d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 7736,
            "upload_time": "2025-02-09T21:42:43",
            "upload_time_iso_8601": "2025-02-09T21:42:43.140714Z",
            "url": "https://files.pythonhosted.org/packages/e1/4e/13d212b4f2ab630b6978fdd58440ff7252e33f4e918fb0910f016e7db135/py2graphql-0.19.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "294020161ee5ab2856994dd38a6ebd5bc122abdc17eca57dd3454c8d875c5d43",
                "md5": "c536b0d5e8f4889d08e49153dd074f40",
                "sha256": "dd078e2fd990c76364ee4b2666957d1d6f0948b37938dcd9679109d9e22a0495"
            },
            "downloads": -1,
            "filename": "py2graphql-0.19.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c536b0d5e8f4889d08e49153dd074f40",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 6513,
            "upload_time": "2025-02-09T21:42:45",
            "upload_time_iso_8601": "2025-02-09T21:42:45.100926Z",
            "url": "https://files.pythonhosted.org/packages/29/40/20161ee5ab2856994dd38a6ebd5bc122abdc17eca57dd3454c8d875c5d43/py2graphql-0.19.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-09 21:42:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "willemt",
    "github_project": "py2graphql",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py2graphql"
}
        
Elapsed time: 1.37428s