A Python client for interacting with GraphQL APIs, offering synchronous, asynchronous, and websocket-based subscription capabilities. It provides simple interfaces for sending queries, mutations, and subscribing to real-time data streams. The current version is 0.4.5, with a relatively active release cadence addressing features and maintenance.
pip install python-graphql-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a synchronous `GraphQLClient`, define a query with variables, execute it, and process the returned JSON data and potential errors. Remember to replace the `GRAPHQL_ENDPOINT` with your actual GraphQL API endpoint.
Explicitly import and instantiate `GraphQLClientAIOHTTP` for async operations or `GraphQLClientWebsockets` for subscriptions.
After calling `client.execute()`, check `response_data.get('errors')` for a list of GraphQL errors and `response_data.get('data')` for successful results.Pass `headers={'Authorization': 'Bearer YOUR_TOKEN'}` to the `GraphQLClient` constructor or `execute` method. For subscriptions, use `GraphQLClientWebsockets(..., init_payload={'headers': {'Authorization': 'Bearer YOUR_TOKEN'}})`.