Simple GraphQL client for Python 2.7+

Overview

python-graphql-client

Simple GraphQL client for Python 2.7+

Install

pip install graphqlclient

Usage

from graphqlclient import GraphQLClient

client = GraphQLClient('http://graphql-swapi.parseapp.com/')

result = client.execute('''
{
  allFilms {
    films {
      title
    }
  }
}
''')

print(result)

Authorization

Authorization tokens can be added to the request using the client's inject_token method:

client.inject_token('very-long-and-secure-token')

which defaults to http header name Authorization. An alternative http header name for the token can be set by passing in the alternative header name, e.g. for x-api-key:

client.inject_token('very-long-and-secure-token','x-api-key')

License

MIT License

Comments
  • Fixed to support python 3

    Fixed to support python 3

    urllib2 doesn't exist within python3. The proposed changes should be compatible with python2 and 3, tested on 2.7.13 and 3.6.0.

    Sorry looks like I commited this early without running more tests, let me refine & push a new update to fix compatibility with both Python2 and 3.

    opened by ssshah86 11
  • 0.2.2 is broken due to missing read me file

    0.2.2 is broken due to missing read me file

    `from setuptools import setup

    with open('README.md', 'r') as fh: long_description = fh.read()

    graphqlclient-0.2.2/ graphqlclient-0.2.2/PKG-INFO graphqlclient-0.2.2/graphqlclient/ graphqlclient-0.2.2/graphqlclient/client.py graphqlclient-0.2.2/graphqlclient/init.py graphqlclient-0.2.2/setup.py graphqlclient-0.2.2/setup.cfg graphqlclient-0.2.2/graphqlclient.egg-info/ graphqlclient-0.2.2/graphqlclient.egg-info/PKG-INFO graphqlclient-0.2.2/graphqlclient.egg-info/not-zip-safe graphqlclient-0.2.2/graphqlclient.egg-info/SOURCES.txt graphqlclient-0.2.2/graphqlclient.egg-info/requires.txt graphqlclient-0.2.2/graphqlclient.egg-info/top_level.txt graphqlclient-0.2.2/graphqlclient.egg-info/dependency_links.txt`

    opened by olorogunthedread 7
  • Certificate error on python 3.7

    Certificate error on python 3.7

    Hi, thanks for this nice little library!

    I ran into a weird issue when using python 3.7 where I would get a certificate error as follows:

    urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)>
    

    The reason why this is weird is because I ran the exact same snippet with python 2.7 and everything worked nicely! Any idea on what might cause this ? Thanks!

    opened by Gabri3l 6
  • Allow the authorization header name to vary

    Allow the authorization header name to vary

    AWS AppSync uses x-api-key instead of Authorization, so I have a need to vary this. I've left it in such a way that 'Authorization' is the default if not specified, to keep this change backwards compatible.

    opened by matthewberryman 3
  • How can I use string.format to inject values into the query?

    How can I use string.format to inject values into the query?

    Since the string starts with {}, this will be interpreted as a key in python's String.format function. What is the best way to programatically include values into the query?

    opened by otmezger 2
  • fix: Remove Bearer from Authorization header

    fix: Remove Bearer from Authorization header

    User should be able to compose their own authorization header. For example AWS API Gateway using Cognito User Pool can not check Authorization header token which has Bearer

    opened by sandangel 0
  • feat: Add parameter to allow error printing suppression

    feat: Add parameter to allow error printing suppression

    Allow for _send to fail silently without printing the error message. Often it is useful to handle (and print) the error outside the _send function. This commit adds a print_err argument (defaults to True), so to suppress the error printing one can simply set this to False.

    This should be especially useful if more sophisticated error handling and logging is implemented to customize the errors without having prints that are neither formatted nor have any debug level associated to it.

    opened by waltner 1
  • urlopen is not closed in client

    urlopen is not closed in client

    i am using this client, but sometimes i get below error, when i checked client.py, i dont see socket connection is closed internally. pls check

    ResourceWarning: unclosed <ssl.SSLSocket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('10.166.23.90', 62047), raddr=('52.217.16.132', 443)> outcome.errors.clear() ResourceWarning: Enable tracemalloc to get the object allocation traceback

    opened by kasarla100 0
  • Simplified GraphQLClient

    Simplified GraphQLClient

    Changes made:

    • Using requests instead of urllib
    • Letting exceptions propagate to caller instead of catching and rethrowing
    • Added generic header injection
    • Deserialize JSON into dict for easier processing
    opened by allfro 0
  • feat: replace print with log

    feat: replace print with log

    when using this client externally, the user sometimes does not want the response to be printed out.

    this PR replaces the print statements with logging.debug statements. if you think this change makes sense but want more flexibility around the log level, i'm willing to extend this PR as well.

    thanks a lot!

    opened by maorfr 0
  • Added self parsing reponse handling.

    Added self parsing reponse handling.

    I also found that I was always parsing the response for json so I just made that a built in option. I realize that this is a breaking change for most people, so I am submitting it as a seperate PR.

    Hope that you do not find this annoying, I am only trying to make the software world a better place.

    opened by ategt 0
Owner
Prisma Labs
Building open source tools to improve the experience of developers | Made with ❤ by @prisma
Prisma Labs
MGE-GraphQL is a Python library for building GraphQL mutations fast and easily

MGE-GraphQL Introduction MGE-GraphQL is a Python library for building GraphQL mutations fast and easily. Data Validations: A similar data validation w

MGE Software 4 Apr 23, 2022
GraphQL security auditing script with a focus on performing batch GraphQL queries and mutations

BatchQL BatchQL is a GraphQL security auditing script with a focus on performing batch GraphQL queries and mutations. This script is not complex, and

Assetnote 267 Dec 24, 2022
A Django GraphQL Starter that uses graphene and graphene_django to interface GraphQL.

Django GraphQL Starter GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data... According to the doc

0101 Solutions 1 Jan 10, 2022
This is a simple Python that will parse instanceStats GraphQL Query into a CSV

GraphQL Python Labs - by Gabs the CSE Table of Contents About The Project Getting Started Prerequisites Installation and Usage Roadmap Contributing Li

Gabriel (Gabs) Cerioni 1 Oct 27, 2021
GraphQL framework for Python

Graphene ?? Join the community on Slack We are looking for contributors! Please check the ROADMAP to see how you can help ❤️ The below readme is the d

GraphQL Python 7.5k Jan 1, 2023
GraphQL framework for Python

Graphene ?? Join the community on Slack We are looking for contributors! Please check the ROADMAP to see how you can help ❤️ The below readme is the d

GraphQL Python 7.5k Jan 1, 2023
Ariadne is a Python library for implementing GraphQL servers using schema-first approach.

Ariadne Ariadne is a Python library for implementing GraphQL servers. Schema-first: Ariadne enables Python developers to use schema-first approach to

Mirumee Labs 1.9k Jan 1, 2023
GraphQL Engine built with Python 3.6+ / asyncio

Tartiflette is a GraphQL Server implementation built with Python 3.6+. Summary Motivation Status Usage Installation Installation dependencies Tartifle

tartiflette 839 Dec 31, 2022
A new GraphQL library for Python 🍓

Strawberry GraphQL Python GraphQL library based on dataclasses Installation ( Quick Start ) The quick start method provides a server and CLI to get go

Strawberry GraphQL 2.8k Jan 1, 2023
A python graphql api, which serves ECB currency rates from last 90 days.

Exchange Rate Api using GraphQL Get Code git pull https://github.com/alaturqua/exchangerate-graphql.git Create .env file with following content and s

Isa 1 Nov 4, 2021
Pygitstats - a package that allows you to use the GitHub GraphQL API with ease in your Python programs

Pygitstats - a package that allows you to use the GitHub GraphQL API with ease in your Python programs

Dillon Barnes 4 Mar 29, 2022
Graphql-codegen library - a pure python implementation

turms DEVELOPMENT Inspiration Turms is a pure python implementation of the awesome graphql-codegen library, following a simliar extensible design. It

Johannes Roos 22 Dec 23, 2022
tartiflette-aiohttp is a wrapper of aiohttp which includes the Tartiflette GraphQL Engine, do not hesitate to take a look of the Tartiflette project.

tartiflette-aiohttp is a wrapper of aiohttp which includes the Tartiflette GraphQL Engine. You can take a look at the Tartiflette API documentation. U

tartiflette 60 Nov 8, 2022
ASGI support for the Tartiflette GraphQL engine

tartiflette-asgi is a wrapper that provides ASGI support for the Tartiflette Python GraphQL engine. It is ideal for serving a GraphQL API over HTTP, o

tartiflette 99 Dec 27, 2022
GraphQL is a query language and execution engine tied to any backend service.

GraphQL The GraphQL specification is edited in the markdown files found in /spec the latest release of which is published at https://graphql.github.io

GraphQL 14k Jan 1, 2023
Integrate GraphQL into your Django project.

Graphene-Django A Django integration for Graphene. ?? Join the community on Slack Documentation Visit the documentation to get started! Quickstart For

GraphQL Python 4k Dec 31, 2022
Adds GraphQL support to your Flask application.

Flask-GraphQL Adds GraphQL support to your Flask application. Usage Just use the GraphQLView view from flask_graphql from flask import Flask from flas

GraphQL Python 1.3k Dec 31, 2022
A library to help construct a graphql-py server supporting react-relay

Relay Library for GraphQL Python GraphQL-relay-py is the Relay library for GraphQL-core. It allows the easy creation of Relay-compliant servers using

GraphQL Python 143 Nov 15, 2022
Django registration and authentication with GraphQL.

Django GraphQL Auth Django registration and authentication with GraphQL. Demo About Abstract all the basic logic of handling user accounts out of your

pedrobern 301 Dec 9, 2022