Package: quiz
Capable GraphQL client for Python.Features:Sync/async compatible, pluggable HTTP clients.Auto-generate typed and documented python APIsORM-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 theissue tracker.QuickstartA quick ‘n dirty request to GitHub’s new V4 API:>>>importquiz>>>query='''
...   {
...     repository(owner: "octocat", name: "Hello-World") {
...       createdAt
...       description
...     }
...   }
... '''>>>quiz.execute(query,url='https://api.github.com/graphql',...auth=('me','password')){"repository":...}FeaturesAdaptability. Built on top ofsnug,
quiz supports different HTTP clientsimportrequestsresult=quiz.execute(query,...,client=requests.Session())as well as async execution
(optionally withaiohttp):result=awaitquiz.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)classRepository(Node,ProjectOwner,Subscribable,Starrable,UniformResourceLocatable,RepositoryInfo,quiz.types.Object)|Arepositorycontainsthecontentforaproject.||Methodresolutionorder:|...||Datadescriptorsdefinedhere:||assignableUsers|:UserConnection|Alistofusersthatcanbeassignedtoissuesinthisrepo||codeOfConduct|:CodeOfConductorNone|Returnsthecodeofconductforthisrepository...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"){createdAtdescription}}Offline query validation. Use the schema to catch errors quickly:>>>schema.query[..._....repository(owner='octocat',name='Hello-World')[..._....createdAt....foo....description...]...]SelectionError:SelectionErroron"Query"atpath"repository":SelectionError:SelectionErroron"Repository"atpath"foo":NoSuchField:fielddoesnotexistDeserialization 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":...}Installationquizand its dependencies are pure python. Installation is easy as:pipinstallquizContributingAfter you’ve cloned the repo locally, set up the development environment
with:makeinitFor quick test runs, run:pytestTo run all tests and checks on various python versions, run:maketestGenerate the docs with:makedocsPull requests welcome!Preliminary roadmapFeaturestatusInput objectsplannedbetter query validation errorsplannedmore examples in docsplannedexecuting selection sets directlyplannedintrospection fields (i.e.__typename)plannedcustom scalars for existing types (e.g.datetime)plannedimprove Object/Interface APIplannedvalue object docsplannedMutations & subscriptionsplannedInline fragmentsplannedFragments and fragment spreadsplannedpy2 unicode robustnessplannedMixing in raw GraphQLplannedModule autogenerationplannedType inference (e.g. enum values)plannedVariablesplannedDirectivesplannedInteger 32-bit limitplannedconverting names from camelcase to snake-caseideaAutogenerate module .rst from schemaideaAutogenerate module .py from schemaideaEscaping python keywordsideaHandling markdown in descriptionsideaWarnings when using deprecated fieldsideaHandle optional types descriptions in schemaideaReturning multiple validation errors at the same timeideaExplicit orderingidea