Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-graphql-client-0.1.1b2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

py_graphql_client-0.1.1b2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file py-graphql-client-0.1.1b2.tar.gz.

File metadata

  • Download URL: py-graphql-client-0.1.1b2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for py-graphql-client-0.1.1b2.tar.gz
Algorithm Hash digest
SHA256 d68211a29c0e5f3d4c17a222df397542811b882577c3e85f683064dfdff2698e
MD5 2c331fec0d2aa5651ad84b7a219cf00c
BLAKE2b-256 0927e30c9085de5e1449edad7514aac5a5f687a440ed2067262fc8d6ebecb5ef

See more details on using hashes here.

File details

Details for the file py_graphql_client-0.1.1b2-py3-none-any.whl.

File metadata

  • Download URL: py_graphql_client-0.1.1b2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

File hashes

Hashes for py_graphql_client-0.1.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8de02f95fc5463946c96dbeb003af2f6d0f61f3bb6c7e5acf32961a6d073a90
MD5 7d6430e28c26fc1e10f095bf28abdd11
BLAKE2b-256 2e1aebe076b4acbae6bd56c93b9f1714b6f32cc9c07fc5fffd0fb3fd8ba1856b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page