Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prodigyeducation/python-graphql-client
Simple module for making requests to a graphQL server in python.
https://github.com/prodigyeducation/python-graphql-client
graphql graphql-client python python-graphql-client
Last synced: about 1 month ago
JSON representation
Simple module for making requests to a graphQL server in python.
- Host: GitHub
- URL: https://github.com/prodigyeducation/python-graphql-client
- Owner: prodigyeducation
- License: mit
- Created: 2020-01-21T03:59:41.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-07T08:23:35.000Z (7 months ago)
- Last Synced: 2024-09-28T21:22:07.196Z (about 2 months ago)
- Topics: graphql, graphql-client, python, python-graphql-client
- Language: Python
- Homepage: https://pypi.org/project/python-graphql-client/
- Size: 72.3 KB
- Stars: 80
- Watchers: 5
- Forks: 21
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![Python CI Checks](https://github.com/prodigyeducation/python-graphql-client/workflows/Python%20CI%20Checks/badge.svg)
![Upload Python Package](https://github.com/prodigyeducation/python-graphql-client/workflows/Upload%20Python%20Package/badge.svg)# Python GraphQL Client
> Simple package for making requests to a graphql server.
## Installation
```bash
pip install python-graphql-client
```## Usage
### Queries & Mutations
```py
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 asynciodata = asyncio.run(client.execute_async(query=query, variables=variables))
print(data) # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}
```### Subscriptions
```py
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 asyncioasyncio.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.'}}
# ...
```## Advanced Usage
### Disable SSL verification
Set the keyword argument `verify=False` ether when instantiating the `GraphqlClient` class.
```py
from python_graphql_client import GraphqlClientclient = GraphqlClient(endpoint="wss://www.your-api.com/graphql", verify=False)
```Alternatively, you can set it when calling the `execute` method.
```py
from python_graphql_client import GraphqlClientclient = GraphqlClient(endpoint="wss://www.your-api.com/graphql"
client.execute(query="", verify=False)
```### Custom Authentication
```py
from requests.auth import HTTPBasicAuth
from python_graphql_client import GraphqlClientauth = HTTPBasicAuth('[email protected]', 'not_a_real_password')
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", auth=auth)
```### Custom Headers
```py
from python_graphql_client import GraphqlClientheaders = { "Authorization": "Token SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV" }
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", headers=headers)
```## 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](docs/CONTRIBUTING.md) documentation for details on the process for submitting pull requests to the project. Also take a peek at our [Code of Conduct](docs/CODE_OF_CONDUCT.md).
## Authors and Acknowledgement
Kudos to @xkludge, @DaleSeo, and @mattbullock for getting this project started.
## License
[MIT License](LICENSE)