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.4.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

simple_graphql_client-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file simple-graphql-client-0.0.4.tar.gz.

File metadata

  • Download URL: simple-graphql-client-0.0.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for simple-graphql-client-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1db213477b79e317a55cb918a0ededf033ae0aa2a0db0f5b4d6f178b1643e185
MD5 52f524576e94062a45d8b91f4b1d22ed
BLAKE2b-256 3837614c57ecbec83e3859243a23e78853e6af51ffacc07235bc0087dd9d5fa2

See more details on using hashes here.

File details

Details for the file simple_graphql_client-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: simple_graphql_client-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for simple_graphql_client-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cdcfd857e8840948ed3c3663ca86fd8eb4548d14bdd2c0ad8ff5e731b4c03084
MD5 628b9d366a370ce062ab7f6f89b2ebce
BLAKE2b-256 a4e248971a22648c42acf00664ee2bd15a83f8349550dff224c4f39c3df4d989

See more details on using hashes here.

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