Skip to main content

Capable GraphQL client

Project description

.. raw:: html

<p align="center">

<img src="" height="150">


<a href="" class="reference external image-reference">
<img src="" alt="Build status">

<a href="" class="reference external image-reference">
<img src="" alt="Test coverage">

<a href="" class="reference external image-reference">
<img src="" alt="Documentation status">


<a href="" class="reference external image-reference">
<img src="" alt="Development status">

<a href="" class="reference external image-reference">
<img src="" alt="Latest version">

<a href="" class="reference external image-reference">
<img src="" alt="License">

<a href="" class="reference external image-reference">
<img src="" alt="Supported python versions">



Capable GraphQL client.


* Sync/async compatible, pluggable HTTP clients.
* Auto-generate typed and documented python APIs
* ORM-like syntax to write GraphQL.

Note that this project is in an early alpha stage.
Some features are not yet implemented (see the roadmap below),
and it may be a little rough around the edges.
If you encounter a problem or have a feature request,
don't hesitate to open an issue in the `issue tracker <>`_.


A quick 'n dirty request to GitHub's new V4 API:

.. code-block:: python3

>>> import quiz
>>> query = '''
... {
... repository(owner: "octocat", name: "Hello-World") {
... createdAt
... description
... }
... }
... '''
>>> quiz.execute(query, url='',
... auth=('me', 'password'))
{"repository": ...}


1. **Adaptability**. Built on top of `snug <>`_,
quiz supports different HTTP clients

.. code-block:: python3

import requests
result = quiz.execute(query, ..., client=requests.Session())

as well as async execution
(optionally with `aiohttp <>`_):

.. code-block:: python3

result = await quiz.execute_async(query, ...)

2. **Typing**.
Convert a GraphQL schema into documented python classes:

.. code-block:: python3

>>> schema = quiz.Schema.from_url('',
... auth=('me', 'password'))
>>> help(schema.Repository)
class Repository(Node, ProjectOwner, Subscribable, Starrable,
UniformResourceLocatable, RepositoryInfo, quiz.types.Object)
| A repository contains the content for a project.
| Method resolution order:
| ...
| Data descriptors defined here:
| assignableUsers
| : UserConnection
| A list of users that can be assigned to issues in this repo
| codeOfConduct
| : CodeOfConduct or None
| Returns the code of conduct for this repository

3. **GraphQL "ORM"**. Write queries as you would with an ORM:

.. code-block:: python3

>>> _ = quiz.SELECTOR
>>> query = schema.query[
... _
... .repository(owner='octocat', name='Hello-World')[
... _
... .createdAt
... .description
... ]
... ]
>>> print(query)
query {
repository(owner: "octocat", name: "Hello-World") {

4. **Offline query validation**. Use the schema to catch errors quickly:

.. code-block:: python3

>>> schema.query[
... _
... .repository(owner='octocat', name='Hello-World')[
... _
... .createdAt
... .foo
... .description
... ]
... ]
SelectionError: SelectionError on "Query" at path "repository":

SelectionError: SelectionError on "Repository" at path "foo":

NoSuchField: field does not exist

5. **Deserialization into python objects**. Responses are loaded into the schema's types.
Use ``.`` to access fields:

.. code-block:: python3

>>> r = quiz.execute(query, ...)
>>> r.repository.description
"My first repository on GitHub!"
>>> isinstance(r.repository, schema.Repository)

If you prefer the raw JSON response, you can always do:

.. code-block:: python3

>>> quiz.execute(str(query), ...)
{"repository": ...}


``quiz`` and its dependencies are pure python. Installation is easy as:

.. code-block:: bash

pip install quiz

Preliminary roadmap

================================================================== ===========
Feature status
================================================================== ===========
Examples working v0.0.3

Input objects v0.0.4
better query validation errors v0.0.4
more examples in docs v0.0.4
executing selection sets directly v0.0.4
introspection fields (i.e. ``__typename``) v0.0.4
custom scalars v0.0.4
improve Object/Interface API v0.0.4
value object docs v0.0.4
Mutations & subscriptions v0.0.4
Inline fragments v0.0.4
Fragments and fragment spreads v0.0.5
py2 unicode robustness v0.0.5
Mixing in raw GraphQL planned
Module autogeneration planned
Type inference (e.g. enum values) planned
Variables planned
Directives planned
Integer 32-bit limit planned
Pickling idea
converting names from camelcase to snake-case idea
Autogenerate module .rst from schema idea
Autogenerate module .py from schema idea
Escaping python keywords idea
Handling markdown in descriptions idea
Warnings when using deprecated fields idea
Handle optional types descriptions in schema idea
Returning multiple validation errors at the same time idea
Explicit ordering idea
================================================================== ===========

Release history


0.0.3 (2018-09-23)

- Established initial public API
- Improved documentation, user guide
- Field aliases
- Deserialization

0.0.2 (2018-08-21)

- Execution of basic GraphQL queries
- Convert GraphQL schema to python types (undocumented)
- Write GraphQL in python syntax (undocumented)


- initial version

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for quiz, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size quiz-0.0.3-py3-none-any.whl (19.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size quiz-0.0.3.tar.gz (23.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page