kirjava


Namekirjava JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://kirjava.samireland.com
SummaryA Python GraphQL client.
upload_time2023-08-21 00:56:49
maintainer
docs_urlNone
authorSam Ireland
requires_python
licenseMIT
keywords graphql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            kirjava
========

|travis| |coveralls| |pypi| |version| |commit|

.. |travis| image:: https://api.travis-ci.org/samirelanduk/kirjava.svg?branch=master
  :target: https://travis-ci.org/samirelanduk/kirjava/

.. |coveralls| image:: https://coveralls.io/repos/github/samirelanduk/kirjava/badge.svg?branch=master
  :target: https://coveralls.io/github/samirelanduk/kirjava/

.. |pypi| image:: https://img.shields.io/pypi/pyversions/kirjava.svg
  :target: https://pypi.org/project/kirjava/

.. |version| image:: https://img.shields.io/pypi/v/kirjava.svg
  :target: https://pypi.org/project/kirjava/

.. |commit| image:: https://img.shields.io/github/last-commit/samirelanduk/kirjava/master.svg
  :target: https://github.com/samirelanduk/kirjava/tree/master/

kirjava is a Python GraphQL client.

Example
-------

    >>> import kirjava
    >>> client = kirjava.Client("https://api.coolsite.com/")
    >>> client.execute("""{ me { name email }}""")
    {'data': {'me': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}


Installing
----------

pip
~~~

kirjava can be installed using pip:

``$ pip3 install kirjava``

If you get permission errors, try using ``sudo``:

``$ sudo pip3 install kirjava``

Or alternatively, consider using a virtual environment.


Development
~~~~~~~~~~~

The repository for kirjava, containing the most recent iteration, can be
found `here <http://github.com/samirelanduk/kirjava/>`_. To clone the
kirjava repository directly from there, use:

``$ git clone git://github.com/samirelanduk/kirjava.git``


Requirements
~~~~~~~~~~~~

kirjava requires `requests <http://docs.python-requests.org/>`_.


Overview
--------

kirjava is a lightweight Python GraphQL client.


Making Queries with a Client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GraphQL services are interacted with using a ``Client`` object:

    >>> import kirjava
    >>> client = kirjava.Client("https://api.coolsite.com/")

The client is associated with a particular URL upon creation.

Queries are then made using the ``execute`` method.

    >>> client.execute("{ me { name email }}")
    {'data': {'me': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}

If authentication tokens need to be added, they can be inserted into the
headers:

    >>> client.headers["Authorization"] = "dani123"

Variables can be passed along with the query:

    >>> client.execute("{ me { name email }}", variables={"var1": 123})

You can instruct the client to retry failed requests:

    >>> client.execute("{ me { name email }}", retries=3, retry_statuses=[500, 502, 503, 504])

You can see all previous queries made by a client:

    >>> client.history
    (({'string': { me { name email }}, 'variables': {'var1': 123}, {'data': {'me
    ': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}), ({'string': {
    me { name email }}, 'variables': {}}, {'data': {'me': {'name': 'Jon Snow', '
    email': 'jon@winterfell.gov.ws'}}}))

Clients use `requests <http://docs.python-requests.org/>`_ sessions internally,
and you can access any cookies set by the server via ``client.session.cookies``.

Uploading Files
~~~~~~~~~~~~~~~

If you want to upload files as part of your request, kirjava can do this. Just
add them as a variable:

    >>> mutation = "mutation sendFile($file: Upload) {sendFile(file: $file) { success }}"
    >>> f = open("local_file.txt", "rb"):
    >>> response = client.execute(mutation, variables={"file": f})
    >>> f.close()

kirjava does this by implementing the
`GraphQL multipart request specification <https://github.com/jaydenseric/graphql-multipart-request-spec>`_
under the hood, and using this if any of the variables supplied are Python file
objects.

Note that the GraphQL server on the other end must be set up to process
multipart requests.


Making Queries without a Client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Alternatively, if creating a dedicated ``Client`` object is somehow
beneath you, and you just want to fire off a quick request without any of that
overhead, there is a module level ``execute`` function:

    >>> kirjava.execute("https://api.coolsite.com/", "{ me { name email }}", headers={"Authorization": "dani123"}, variables={"var1": 123})


Changelog
---------

Release 0.4.0
~~~~~~~~~~~~~

`21 August 2023`

* You can retry failed requests.


Release 0.3.0
~~~~~~~~~~~~~

`6 August 2020`

* File upload array type now supported.


Release 0.2.0
~~~~~~~~~~~~~

`11 December 2020`

* Implements GraphQL multipart request specification to allow file upload.
* Refactored kirjava.py into full package.


Release 0.1.3
~~~~~~~~~~~~~

`16 November 2020`

* Provides access to requests cookie jar.
* Better handling of non-JSON responses.


Release 0.1.2
~~~~~~~~~~~~~

`1 April 2019`

* Added module-level execute function.


Release 0.1.1
~~~~~~~~~~~~~

`30 March 2019`

* Added tests.
* Clients now store history of their queries.


Release 0.1.0
~~~~~~~~~~~~~

`23 March 2019`

* Created basic Client.



            

Raw data

            {
    "_id": null,
    "home_page": "https://kirjava.samireland.com",
    "name": "kirjava",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "GraphQL",
    "author": "Sam Ireland",
    "author_email": "mail@samireland.com",
    "download_url": "",
    "platform": null,
    "description": "kirjava\n========\n\n|travis| |coveralls| |pypi| |version| |commit|\n\n.. |travis| image:: https://api.travis-ci.org/samirelanduk/kirjava.svg?branch=master\n  :target: https://travis-ci.org/samirelanduk/kirjava/\n\n.. |coveralls| image:: https://coveralls.io/repos/github/samirelanduk/kirjava/badge.svg?branch=master\n  :target: https://coveralls.io/github/samirelanduk/kirjava/\n\n.. |pypi| image:: https://img.shields.io/pypi/pyversions/kirjava.svg\n  :target: https://pypi.org/project/kirjava/\n\n.. |version| image:: https://img.shields.io/pypi/v/kirjava.svg\n  :target: https://pypi.org/project/kirjava/\n\n.. |commit| image:: https://img.shields.io/github/last-commit/samirelanduk/kirjava/master.svg\n  :target: https://github.com/samirelanduk/kirjava/tree/master/\n\nkirjava is a Python GraphQL client.\n\nExample\n-------\n\n    >>> import kirjava\n    >>> client = kirjava.Client(\"https://api.coolsite.com/\")\n    >>> client.execute(\"\"\"{ me { name email }}\"\"\")\n    {'data': {'me': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}\n\n\nInstalling\n----------\n\npip\n~~~\n\nkirjava can be installed using pip:\n\n``$ pip3 install kirjava``\n\nIf you get permission errors, try using ``sudo``:\n\n``$ sudo pip3 install kirjava``\n\nOr alternatively, consider using a virtual environment.\n\n\nDevelopment\n~~~~~~~~~~~\n\nThe repository for kirjava, containing the most recent iteration, can be\nfound `here <http://github.com/samirelanduk/kirjava/>`_. To clone the\nkirjava repository directly from there, use:\n\n``$ git clone git://github.com/samirelanduk/kirjava.git``\n\n\nRequirements\n~~~~~~~~~~~~\n\nkirjava requires `requests <http://docs.python-requests.org/>`_.\n\n\nOverview\n--------\n\nkirjava is a lightweight Python GraphQL client.\n\n\nMaking Queries with a Client\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nGraphQL services are interacted with using a ``Client`` object:\n\n    >>> import kirjava\n    >>> client = kirjava.Client(\"https://api.coolsite.com/\")\n\nThe client is associated with a particular URL upon creation.\n\nQueries are then made using the ``execute`` method.\n\n    >>> client.execute(\"{ me { name email }}\")\n    {'data': {'me': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}\n\nIf authentication tokens need to be added, they can be inserted into the\nheaders:\n\n    >>> client.headers[\"Authorization\"] = \"dani123\"\n\nVariables can be passed along with the query:\n\n    >>> client.execute(\"{ me { name email }}\", variables={\"var1\": 123})\n\nYou can instruct the client to retry failed requests:\n\n    >>> client.execute(\"{ me { name email }}\", retries=3, retry_statuses=[500, 502, 503, 504])\n\nYou can see all previous queries made by a client:\n\n    >>> client.history\n    (({'string': { me { name email }}, 'variables': {'var1': 123}, {'data': {'me\n    ': {'name': 'Jon Snow', 'email': 'jon@winterfell.gov.ws'}}}), ({'string': {\n    me { name email }}, 'variables': {}}, {'data': {'me': {'name': 'Jon Snow', '\n    email': 'jon@winterfell.gov.ws'}}}))\n\nClients use `requests <http://docs.python-requests.org/>`_ sessions internally,\nand you can access any cookies set by the server via ``client.session.cookies``.\n\nUploading Files\n~~~~~~~~~~~~~~~\n\nIf you want to upload files as part of your request, kirjava can do this. Just\nadd them as a variable:\n\n    >>> mutation = \"mutation sendFile($file: Upload) {sendFile(file: $file) { success }}\"\n    >>> f = open(\"local_file.txt\", \"rb\"):\n    >>> response = client.execute(mutation, variables={\"file\": f})\n    >>> f.close()\n\nkirjava does this by implementing the\n`GraphQL multipart request specification <https://github.com/jaydenseric/graphql-multipart-request-spec>`_\nunder the hood, and using this if any of the variables supplied are Python file\nobjects.\n\nNote that the GraphQL server on the other end must be set up to process\nmultipart requests.\n\n\nMaking Queries without a Client\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nAlternatively, if creating a dedicated ``Client`` object is somehow\nbeneath you, and you just want to fire off a quick request without any of that\noverhead, there is a module level ``execute`` function:\n\n    >>> kirjava.execute(\"https://api.coolsite.com/\", \"{ me { name email }}\", headers={\"Authorization\": \"dani123\"}, variables={\"var1\": 123})\n\n\nChangelog\n---------\n\nRelease 0.4.0\n~~~~~~~~~~~~~\n\n`21 August 2023`\n\n* You can retry failed requests.\n\n\nRelease 0.3.0\n~~~~~~~~~~~~~\n\n`6 August 2020`\n\n* File upload array type now supported.\n\n\nRelease 0.2.0\n~~~~~~~~~~~~~\n\n`11 December 2020`\n\n* Implements GraphQL multipart request specification to allow file upload.\n* Refactored kirjava.py into full package.\n\n\nRelease 0.1.3\n~~~~~~~~~~~~~\n\n`16 November 2020`\n\n* Provides access to requests cookie jar.\n* Better handling of non-JSON responses.\n\n\nRelease 0.1.2\n~~~~~~~~~~~~~\n\n`1 April 2019`\n\n* Added module-level execute function.\n\n\nRelease 0.1.1\n~~~~~~~~~~~~~\n\n`30 March 2019`\n\n* Added tests.\n* Clients now store history of their queries.\n\n\nRelease 0.1.0\n~~~~~~~~~~~~~\n\n`23 March 2019`\n\n* Created basic Client.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python GraphQL client.",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://kirjava.samireland.com"
    },
    "split_keywords": [
        "graphql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "154ba38420b0e7a3546ea7fa77ef63da4d62b0d06453d4903fea6af832f5f5ff",
                "md5": "e8c5b8c98a9982cb0124a9f7c4b05141",
                "sha256": "6db25e9de35af7aa5fbb1c1bcff74616402b3595745518bd44fdd880b3beb000"
            },
            "downloads": -1,
            "filename": "kirjava-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8c5b8c98a9982cb0124a9f7c4b05141",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7902,
            "upload_time": "2023-08-21T00:56:49",
            "upload_time_iso_8601": "2023-08-21T00:56:49.024477Z",
            "url": "https://files.pythonhosted.org/packages/15/4b/a38420b0e7a3546ea7fa77ef63da4d62b0d06453d4903fea6af832f5f5ff/kirjava-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-21 00:56:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "kirjava"
}
        
Elapsed time: 0.31874s