Giter Club home page Giter Club logo

quiz's Introduction

Quiz


Build status Test coverage Dependabot Documentation status
Development status Latest version License Supported python versions

Capable GraphQL client.

Features:

  • 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.

Quickstart

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

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

Features

  1. Adaptability. Built on top of snug, quiz supports different HTTP clients

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

    as well as async execution (optionally with aiohttp):

    result = await quiz.execute_async(query, ...)
  2. Typing. Convert a GraphQL schema into documented python classes:

    >>> schema = quiz.Schema.from_url('https://api.github.com/graphql',
    ...                               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:

    >>> _ = quiz.SELECTOR
    >>> query = schema.query[
    ...     _
    ...     .repository(owner='octocat', name='Hello-World')[
    ...         _
    ...         .createdAt
    ...         .description
    ...     ]
    ... ]
    >>> str(query)
    query {
      repository(owner: "octocat", name: "Hello-World") {
        createdAt
        description
      }
    }
  4. Offline query validation. Use the schema to catch errors quickly:

    >>> 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:

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

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

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

Installation

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

pip install quiz

Contributing

After you've cloned the repo locally, set up the development environment with:

make init

For quick test runs, run:

pytest

To run all tests and checks on various python versions, run:

make test

Generate the docs with:

make docs

Pull requests welcome!

Preliminary roadmap

Feature status
Input objects v0.2.0
better query validation errors v0.2.0
more examples in docs v0.2.0
executing selection sets directly v0.2.0
introspection fields (i.e. __typename) v0.2.0
custom scalars for existing types (e.g. datetime) v0.2.0
improve Object/Interface API v0.2.0
value object docs v0.2.0
Mutations & subscriptions v0.2.0
Inline fragments v0.2.0
Fragments and fragment spreads v0.3.0
py2 unicode robustness v0.3.0
Mixing in raw GraphQL planned
Module autogeneration planned
Type inference (e.g. enum values) planned
Variables planned
Directives planned
Integer 32-bit limit planned
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

quiz's People

Contributors

ariebovenberg avatar dependabot-support avatar rmarren1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.