Python GraphQL Client
Simple package for making requests to a graphql server.
Installation
pip install python-graphql-client
Usage
from python_graphql_client import GraphqlClient
client = GraphqlClient(endpoint="https://countries.trevorblades.com")
query = """
query countryQuery($countryCode: String) {
country(code:$countryCode) {
code
name
}
}
"""
variables = {"countryCode": "CA"}
data = client.execute(query=query, variables=variables)
print(data)
import asyncio
data = asyncio.run(client.execute_async(query=query, variables=variables))
print(data)
from python_graphql_client import GraphqlClient
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql")
query = """
subscription onMessageAdded {
messageAdded
}
"""
import asyncio
asyncio.run(client.subscribe(query=query, handle=print))
Advanced Usage
Disable SSL verification
Set the keyword argument verify=False
ether when instantiating the GraphqlClient
class.
from python_graphql_client import GraphqlClient
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", verify=False)
Alternatively, you can set it when calling the execute
method.
from python_graphql_client import GraphqlClient
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql"
client.execute(query="<Your Query>", verify=False)
Custom Authentication
from requests.auth import HTTPBasicAuth
from python_graphql_client import GraphqlClient
auth = HTTPBasicAuth('fake@example.com', 'not_a_real_password')
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", auth=auth)
Roadmap
To start we'll try and use a Github project board for listing current work and updating priorities of upcoming features.
Contributing
Read the Contributing documentation for details on the process for submitting pull requests to the project. Also take a peek at our Code of Conduct.
Authors and Acknowledgement
Kudos to @xkludge, @DaleSeo, and @mattbullock for getting this project started.
License
MIT License