Python GraphQL Client
Project description
Python GraphQL Client
Simple package for making requests to a graphql server.
Installation
pip install python-graphql-client
Usage
- Query/Mutation
from python_graphql_client import GraphqlClient
# Instantiate the client with an endpoint.
client = GraphqlClient(endpoint="https://countries.trevorblades.com")
# Create the query string and variables required for the request.
query = """
query countryQuery($countryCode: String) {
country(code:$countryCode) {
code
name
}
}
"""
variables = {"countryCode": "CA"}
# Synchronous request
data = client.execute(query=query, variables=variables)
print(data) # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}
# Asynchronous request
import asyncio
data = asyncio.run(client.execute_async(query=query, variables=variables))
print(data) # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}
- Subscription
from python_graphql_client import GraphqlClient
# Instantiate the client with a websocket endpoint.
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql")
# Create the query string and variables required for the request.
query = """
subscription onMessageAdded {
messageAdded
}
"""
# Asynchronous request
import asyncio
asyncio.run(client.subscribe(query=query, handle=print))
# => {'data': {'messageAdded': 'Error omnis quis.'}}
# => {'data': {'messageAdded': 'Enim asperiores omnis.'}}
# => {'data': {'messageAdded': 'Unde ullam consequatur quam eius vel.'}}
# ...
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
Project details
Release history Release notifications | RSS feed
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 python_graphql_client-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bcf3b2f36a1f418aabfa3317235350e11d824eff4b40c730181153c74244755 |
|
MD5 | 4ca08ebe4ee376f8bdd540141ce06b22 |
|
BLAKE2b-256 | 30f95e7786288ee103c8d4ece99ecbb1079ca35b8b009155f82c95733da87307 |
Close
Hashes for python_graphql_client-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8c35d305aa408875338ec6720538fed90ddd2a1e30cf79cbb0ab38729fc7f2c |
|
MD5 | 8f8c3d3de18ebc281b3bf59a0dd5a8a2 |
|
BLAKE2b-256 | 1298c5c199917e444b79090165500c7db678370f19fafcca05fd95162eeab02a |