Skip to main content

A simple graphql client which also supports file upload

Project description

Simple GraphQL Client

Installation

The client is available on PyPI:

  • $ pip install simple-graphql-client

Examples

Executing a query

from simple_graphql_client import GraphQLClient

headers = {'Authorization': 'Bearer ...'}

client = GraphQLClient("https://...", headers=headers)

query = "..."

variables = {
    ...
}
data = client.query(query=query, variables=variables)

Executing a query with a single file

Note: For information visit: https://github.com/jaydenseric/graphql-multipart-request-spec

from simple_graphql_client import GraphQLClient

headers = {'Authorization': 'Bearer ...'}

client = GraphQLClient("https://...", headers=headers)

query = "..."
filename = "..."
variables = {
    ...
    'file': None,
    ...
}

with open(filename, "rb") as file:
    files = [
        ('file', (filename, file))
    ]

    response = client.query_with_files(query=query, variables=variables, files=files)

Executing a query with a multiple files

from simple_graphql_client import GraphQLClient

client = GraphQLClient("https://...")

query = "..."
filenames = ["...", "..."]
files = []
variables = {
    ...
    'files': [None, None]
    ... 
}

for i, filename in enumerate(filenames):
    variable = 'files.{}'.format(i)
    files.append((variable, (filename, open(filename, "rb"))))

response = client.query_with_files(query=query, variables=variables, files=files)

Setting a query-specific header

This argument will override the default header which can be set in the GraphQLClient

response = client.query(query=query, variables=variables, files=files, headers=headers)
response = client.query_with_files(query=query, variables=variables, files=files, headers=headers)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-graphql-client-0.0.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

simple_graphql_client-0.0.2-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page