🎱 Quiz
Capable GraphQL client for Python.
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/graphql',
... auth=('me', 'password'))
{"repository": ...}
Features
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, ...)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 ...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 } }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 existDeserialization 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) TrueIf 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 |
planned |
better query validation errors |
planned |
more examples in docs |
planned |
executing selection sets directly |
planned |
introspection fields (i.e. __typename) |
planned |
custom scalars for existing types (e.g. datetime) |
planned |
improve Object/Interface API |
planned |
value object docs |
planned |
Mutations & subscriptions |
planned |
Inline fragments |
planned |
Fragments and fragment spreads |
planned |
py2 unicode robustness |
planned |
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 |
Metadata
Release files for quiz 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quiz-0.3.2.tar.gz | 24.3 kB | Without provenance | Details for quiz-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quiz-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for quiz-0.3.2-py3-none-any.whl |
Total release size: 51.7 kB
Release files / quiz-0.3.2.tar.gz
| Download URL | quiz-0.3.2.tar.gz |
|---|---|
| Size | 24.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4e858e7ea4ee269d22210d0b5f0203847a475e687d4f5d81bcc6f0c1b713cce
|
|
BLAKE2b-256 checksum How to use checksums |
5e73abbfd74a332c0ce66b948494d12f74a03036e093f245f82e98bca2a4ca76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|
Release files / quiz-0.3.2-py3-none-any.whl
| Download URL | quiz-0.3.2-py3-none-any.whl |
|---|---|
| Size | 27.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4d58c1ac196450e263a1e6a644ce2410cf6cdaa94982f19d936f3d4484eb6e3
|
|
BLAKE2b-256 checksum How to use checksums |
1f99b0ee3b910778b8f87e76f7d1c3785e866186fbf49c91ab6960a56359e474
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|
Security for quiz 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.