• Stars
    star
    1,474
  • Rank 30,762 (Top 0.7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 30 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GraphQL client in Python

GQL

This is a GraphQL client for Python 3.7+. 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.

GitHub-Actions pyversion pypi Anaconda-Server Badge codecov

Documentation

The complete documentation for GQL can be found at gql.readthedocs.io.

Features

Installation

You can install GQL with all the optional dependencies using pip:

# Quotes may be required on certain shells such as zsh.
pip install "gql[all]"

NOTE: See also the documentation to install GQL with less extra dependencies depending on the transports you would like to use or for alternative installation methods.

Usage

Basic usage

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# Select your transport with a defined url endpoint
transport = AIOHTTPTransport(url="https://countries.trevorblades.com/")

# Create a GraphQL client using the defined transport
client = Client(transport=transport, fetch_schema_from_transport=True)

# Provide a GraphQL query
query = gql(
    """
    query getContinents {
      continents {
        code
        name
      }
    }
"""
)

# Execute the query on the transport
result = client.execute(query)
print(result)

Executing the above code should output the following result:

$ python basic_example.py
{'continents': [{'code': 'AF', 'name': 'Africa'}, {'code': 'AN', 'name': 'Antarctica'}, {'code': 'AS', 'name': 'Asia'}, {'code': 'EU', 'name': 'Europe'}, {'code': 'NA', 'name': 'North America'}, {'code': 'OC', 'name': 'Oceania'}, {'code': 'SA', 'name': 'South America'}]}

WARNING: Please note that this basic example won't work if you have an asyncio event loop running. In some python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you. In that case you should use instead the async usage example.

Contributing

See CONTRIBUTING.md

License

MIT License

More Repositories

1

graphene

GraphQL framework for Python
Python
7,978
star
2

graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
Python
4,235
star
3

flask-graphql

Adds GraphQL support to your Flask application.
Python
1,316
star
4

graphene-sqlalchemy

Graphene SQLAlchemy integration
Python
971
star
5

graphql-core

A Python 3.6+ port of the GraphQL.js reference implementation of GraphQL.
Python
498
star
6

graphql-core-legacy

GraphQL base implementation for Python (legacy version – see graphql-core for the current one)
Python
375
star
7

graphene-mongo

Graphene MongoEngine integration
Python
285
star
8

graphql-ws

GraphQL websockets
Python
271
star
9

graphene-pydantic

Integrate GraphQL with your Pydantic models
Python
220
star
10

swapi-graphene

GraphQL Starwars API using Graphene and Django
Python
172
star
11

sanic-graphql

Adds GraphQL support to your Sanic app.
Python
149
star
12

graphql-relay-py

A library to help construct a graphql-py server supporting react-relay
Python
145
star
13

aiohttp-graphql

Adds GraphQL support to your aiohttp app.
Python
118
star
14

graphene-gae

GraphQL Support for Google AppEngine [DEPRECATED - Looking for maintainers]
Python
117
star
15

graphql-server

This is the core package for using GraphQL in a custom server easily
Python
114
star
16

gql-next

A Python GraphQL Client library providing ability to validate and make type-safe GraphQL calls
Python
76
star
17

graphene-tornado

Python
52
star
18

graphene-federation

Federation implementation for Graphene.
Python
40
star
19

webob-graphql

GraphQL integration for WebOb based frameworks: Pyramid, Pylons...
Python
28
star
20

GraphQL-SublimeText

GraphQL language syntax for SublimeText
17
star
21

graphene-python.org

Graphene-Python.org official website
JavaScript
6
star