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
Built Distribution
Close
Hashes for simple-graphql-client-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75f7ded405d42b66a5b0f4c15a0e5e1a62cc11344015c1e0d9afc580c4802400 |
|
MD5 | f3e66ded00cd2552d0b51bda8766a11d |
|
BLAKE2b-256 | 25141636b6a8425ad02ca32f9fd1018bc739bec4ab6a784cdecc99cd5679dbd6 |
Close
Hashes for simple_graphql_client-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35c84c128def80a2277ee949e88b9b3eef20606337a9ee60d873d89d2b75004e |
|
MD5 | 768b22ee169eea96cc2eb3616d62ce75 |
|
BLAKE2b-256 | 8e4972e9e734ea59f04b2f83eb2d30f002304303b57d927b08ac542b9606c7a2 |