python-graphql-client


Namepython-graphql-client JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/prodigyeducation/python-graphql-client
SummaryPython GraphQL Client
upload_time2021-03-04 21:32:04
maintainer
docs_urlNone
authorJustin Krinke
requires_python
licenseMIT
keywords api graphql client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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.

<!-- Badges here. -->

## Installation

```bash
pip install python-graphql-client
```

## Usage

- Query/Mutation

```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 asyncio

data = asyncio.run(client.execute_async(query=query, variables=variables))
print(data)  # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}
```

- Subscription

```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 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.'}}
# ...
```

## Advanced Usage

### Disable SSL verification

Set the keyword argument `verify=False` ether when instantiating the `GraphqlClient` class.

```py
from python_graphql_client import GraphqlClient

client = 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 GraphqlClient

client = GraphqlClient(endpoint="wss://www.your-api.com/graphql"
client.execute(query="<Your Query>", verify=False)
```

### Custom Authentication

```py
from requests.auth import HTTPBasicAuth
from python_graphql_client import GraphqlClient

auth = HTTPBasicAuth('fake@example.com', 'not_a_real_password')
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", auth=auth)
```

## 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)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/prodigyeducation/python-graphql-client",
    "name": "python-graphql-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "api graphql client",
    "author": "Justin Krinke",
    "author_email": "opensource@prodigygame.com",
    "download_url": "https://files.pythonhosted.org/packages/04/bf/6ebd129e957c3fd8ea1c36ae03cbd68e2342ec2bea7010d5379bd363da06/python_graphql_client-0.4.3.tar.gz",
    "platform": "",
    "description": "[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n![Python CI Checks](https://github.com/prodigyeducation/python-graphql-client/workflows/Python%20CI%20Checks/badge.svg)\n![Upload Python Package](https://github.com/prodigyeducation/python-graphql-client/workflows/Upload%20Python%20Package/badge.svg)\n\n# Python GraphQL Client\n\n> Simple package for making requests to a graphql server.\n\n<!-- Badges here. -->\n\n## Installation\n\n```bash\npip install python-graphql-client\n```\n\n## Usage\n\n- Query/Mutation\n\n```py\nfrom python_graphql_client import GraphqlClient\n\n# Instantiate the client with an endpoint.\nclient = GraphqlClient(endpoint=\"https://countries.trevorblades.com\")\n\n# Create the query string and variables required for the request.\nquery = \"\"\"\n    query countryQuery($countryCode: String) {\n        country(code:$countryCode) {\n            code\n            name\n        }\n    }\n\"\"\"\nvariables = {\"countryCode\": \"CA\"}\n\n# Synchronous request\ndata = client.execute(query=query, variables=variables)\nprint(data)  # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}\n\n\n# Asynchronous request\nimport asyncio\n\ndata = asyncio.run(client.execute_async(query=query, variables=variables))\nprint(data)  # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}\n```\n\n- Subscription\n\n```py\nfrom python_graphql_client import GraphqlClient\n\n# Instantiate the client with a websocket endpoint.\nclient = GraphqlClient(endpoint=\"wss://www.your-api.com/graphql\")\n\n# Create the query string and variables required for the request.\nquery = \"\"\"\n    subscription onMessageAdded {\n        messageAdded\n    }\n\"\"\"\n\n# Asynchronous request\nimport asyncio\n\nasyncio.run(client.subscribe(query=query, handle=print))\n# => {'data': {'messageAdded': 'Error omnis quis.'}}\n# => {'data': {'messageAdded': 'Enim asperiores omnis.'}}\n# => {'data': {'messageAdded': 'Unde ullam consequatur quam eius vel.'}}\n# ...\n```\n\n## Advanced Usage\n\n### Disable SSL verification\n\nSet the keyword argument `verify=False` ether when instantiating the `GraphqlClient` class.\n\n```py\nfrom python_graphql_client import GraphqlClient\n\nclient = GraphqlClient(endpoint=\"wss://www.your-api.com/graphql\", verify=False)\n```\n\nAlternatively, you can set it when calling the `execute` method.\n\n```py\nfrom python_graphql_client import GraphqlClient\n\nclient = GraphqlClient(endpoint=\"wss://www.your-api.com/graphql\"\nclient.execute(query=\"<Your Query>\", verify=False)\n```\n\n### Custom Authentication\n\n```py\nfrom requests.auth import HTTPBasicAuth\nfrom python_graphql_client import GraphqlClient\n\nauth = HTTPBasicAuth('fake@example.com', 'not_a_real_password')\nclient = GraphqlClient(endpoint=\"wss://www.your-api.com/graphql\", auth=auth)\n```\n\n## Roadmap\n\nTo start we'll try and use a Github project board for listing current work and updating priorities of upcoming features.\n\n## Contributing\n\nRead 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).\n\n## Authors and Acknowledgement\n\nKudos to @xkludge, @DaleSeo, and @mattbullock for getting this project started.\n\n## License\n\n[MIT License](LICENSE)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python GraphQL Client",
    "version": "0.4.3",
    "project_urls": {
        "Homepage": "https://github.com/prodigyeducation/python-graphql-client"
    },
    "split_keywords": [
        "api",
        "graphql",
        "client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "942320e60e8ce635aaef99962e3d1d0f0b3e0e9632e1bd0aeb6b6cb8436a1fa3",
                "md5": "133a21a5091897d3e07b84dc86ba3b24",
                "sha256": "c5eb996702acf46110b352f61819c46065ea4f4f106158535cd471e66490b25e"
            },
            "downloads": -1,
            "filename": "python_graphql_client-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "133a21a5091897d3e07b84dc86ba3b24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4945,
            "upload_time": "2021-03-04T21:32:03",
            "upload_time_iso_8601": "2021-03-04T21:32:03.077093Z",
            "url": "https://files.pythonhosted.org/packages/94/23/20e60e8ce635aaef99962e3d1d0f0b3e0e9632e1bd0aeb6b6cb8436a1fa3/python_graphql_client-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04bf6ebd129e957c3fd8ea1c36ae03cbd68e2342ec2bea7010d5379bd363da06",
                "md5": "7fa593ac75bb76b5eb52226ca896b99c",
                "sha256": "fdbd03115dde8776db02e60414b83b018d7d95e5752d6d5fabf21c99265f5b9d"
            },
            "downloads": -1,
            "filename": "python_graphql_client-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "7fa593ac75bb76b5eb52226ca896b99c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4140,
            "upload_time": "2021-03-04T21:32:04",
            "upload_time_iso_8601": "2021-03-04T21:32:04.250903Z",
            "url": "https://files.pythonhosted.org/packages/04/bf/6ebd129e957c3fd8ea1c36ae03cbd68e2342ec2bea7010d5379bd363da06/python_graphql_client-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-04 21:32:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "prodigyeducation",
    "github_project": "python-graphql-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-graphql-client"
}
        
Elapsed time: 0.32504s