gituser/production/: gql-2.0.0 metadata and description

Homepage Simple index

GraphQL client for Python

author Syrus Akbary
author_email me@syrusakbary.com
classifiers
  • Development Status :: 3 - Alpha
  • Intended Audience :: Developers
  • Topic :: Software Development :: Libraries
  • Programming Language :: Python :: 2
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.5
  • Programming Language :: Python :: 3.6
  • Programming Language :: Python :: 3.7
  • Programming Language :: Python :: 3.8
  • Programming Language :: Python :: Implementation :: PyPy
description_content_type text/markdown
keywords api graphql protocol rest relay gql client
license MIT
provides_extras test
requires_dist
  • six (>=1.10.0)
  • graphql-core (<3,>=2.3.2)
  • promise (<3,>=2.3)
  • requests (<3,>=2.12)
  • flake8 (==3.8.1) ; extra == 'dev'
  • isort (==4.3.21) ; extra == 'dev'
  • black (==19.10b0) ; extra == 'dev'
  • mypy (==0.770) ; extra == 'dev'
  • check-manifest (<1,>=0.42) ; extra == 'dev'
  • pytest (==5.4.2) ; extra == 'dev'
  • pytest-asyncio (==0.11.0) ; extra == 'dev'
  • pytest-cov (==2.8.1) ; extra == 'dev'
  • mock (==4.0.2) ; extra == 'dev'
  • vcrpy (==4.0.2) ; extra == 'dev'
  • coveralls (==2.0.0) ; extra == 'dev'
  • pytest (==5.4.2) ; extra == 'test'
  • pytest-asyncio (==0.11.0) ; extra == 'test'
  • pytest-cov (==2.8.1) ; extra == 'test'
  • mock (==4.0.2) ; extra == 'test'
  • vcrpy (==4.0.2) ; extra == 'test'
  • coveralls (==2.0.0) ; extra == 'test'
File Tox results History
gql-2.0.0-py2.py3-none-any.whl
Size
10 KB
Type
Python Wheel
Python
2.7

GQL

This is a GraphQL client for Python. Plays nicely with graphene, graphql-core, graphql-js and any other GraphQL implementation compatible with the spec.

GQL architecture is inspired by React-Relay and Apollo-Client.

travis pyversion pypi Anaconda-Server Badge coveralls

Installation

$ pip install gql

Usage

The example below shows how you can execute queries against a local schema.

from gql import gql, Client

from .someSchema import SampleSchema


client = Client(schema=SampleSchema)
query = gql('''
    {
      hello
    }
''')

client.execute(query)

If you want to add additional headers when executing the query, you can specify these in a transport object:

from gql import Client
from gql.transport.requests import RequestsHTTPTransport

from .someSchema import SampleSchema

client = Client(transport=RequestsHTTPTransport(
     url='/graphql', headers={'Authorization': 'token'}), schema=SampleSchema)

To execute against a graphQL API. (We get the schema by using introspection).

from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport

sample_transport=RequestsHTTPTransport(
    url='https://countries.trevorblades.com/',
    use_json=True,
    headers={
        "Content-type": "application/json",
    },
    verify=False,
    retries=3,
)

client = Client(
    transport=sample_transport,
    fetch_schema_from_transport=True,
)

query = gql('''
    query getContinents {
      continents {
        code
        name
      }
    }
''')

client.execute(query)

If you have a local schema stored as a schema.graphql file, you can do:

from graphql import build_ast_schema, parse
from gql import gql, Client

with open('path/to/schema.graphql') as source:
    document = parse(source.read())

schema = build_ast_schema(document)

client = Client(schema=schema)
query = gql('''
    {
      hello
    }
''')

client.execute(query)

Contributing

See CONTRIBUTING.md

License

MIT License