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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ead1e177eef9a48d767ba03aa222e4a7fde965a525c4335e1e74d1b83ba1318f |
|
MD5 | 60f5741642cf532459703133f5112c43 |
|
BLAKE2b-256 | 5896a17ea754038b88c4f8d51430f4cb2104e668d4c724c9b6bb8573bdd1851f |
Close
Hashes for simple_graphql_client-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9276d8380db1e515baeec2207b4fd5c1d41e769168050f10c98addfc04826647 |
|
MD5 | 356cec41061dbdb578844266afa3a42c |
|
BLAKE2b-256 | a97a16cf1955f76a4a93166c3bc15d5a46fefa96de4f3ea87c7d64d6cf771469 |