A dead-simple graphql client that supports subscriptions over websockets.
Project description
py-graphql-client
Dead-simple to use GraphQL client over websocket. Using the apollo-transport-ws protocol.
Install
pip install py-graphql-client
Examples
Setup subscriptions super easily
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
def callback(_id, data):
print("got new data..")
print(f"msg id: {_id}. data: {data}")
query = """
subscription {
notifications {
id
title
content
}
}
"""
sub_id = ws.subscribe(query, callback=callback)
...
# later stop the subscription
ws.stop_subscribe(sub_id)
ws.close()
Variables can be passed
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
def callback(_id, data):
print("got new data..")
print(f"msg id: {_id}. data: {data}")
query = """
subscription ($limit: Int!) {
notifications (order_by: {created: "desc"}, limit: $limit) {
id
title
content
}
}
"""
sub_id = ws.subscribe(query, variables={'limit': 10}, callback=callback)
Normal queries and mutations work too
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
query = """
query ($limit: Int!) {
notifications (order_by: {created: "desc"}, limit: $limit) {
id
title
content
}
}
"""
res = ws.query(query, variables={'limit': 10})
print(res)
ws.close()
TODO
- tests
- support http as well
- should use asyncio websocket library?
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 py-graphql-client-0.1.1b1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 085f243bb1d4cdaf84dc6960a7096dee2cd8b1c4cd70f50250a0bf25f1600c1b |
|
MD5 | ec01338019e87ffd967909facecd7035 |
|
BLAKE2b-256 | 5c9d4c1d739601345bca4bacd30950713e13d68e4bc26679c7f2ba688fc863d5 |
Close
Hashes for py_graphql_client-0.1.1b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48adfa962e3817db15a21e1507bd4b610310a5b4dfceef01eaa7850242be56ba |
|
MD5 | c58aeddc1c18e8bf007c9421f8b4eefd |
|
BLAKE2b-256 | 504de8e30b6b746c88f4263ef14335a5f35fa7cbdbbd458fba7f62d47059311f |