Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doctorjohn/aiogqlc
Python aynchronous/IO GraphQL client with file upload and subscription support.
https://github.com/doctorjohn/aiogqlc
aiohttp aiohttp-client asyncio graphql graphql-client graphql-library graphql-subscriptions graphql-ws python python3
Last synced: 5 days ago
JSON representation
Python aynchronous/IO GraphQL client with file upload and subscription support.
- Host: GitHub
- URL: https://github.com/doctorjohn/aiogqlc
- Owner: DoctorJohn
- License: mit
- Created: 2020-03-13T16:07:04.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-24T00:53:00.000Z (about 2 months ago)
- Last Synced: 2025-01-31T12:07:57.060Z (12 days ago)
- Topics: aiohttp, aiohttp-client, asyncio, graphql, graphql-client, graphql-library, graphql-subscriptions, graphql-ws, python, python3
- Language: Python
- Homepage: https://doctorjohn.github.io/aiogqlc/
- Size: 795 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# Asynchronous/IO GraphQL client
[![Versions][versions-image]][versions-url]
[![PyPI][pypi-image]][pypi-url]
[![Downloads][downloads-image]][downloads-url]
[![Codecov][codecov-image]][codecov-url]
[![License][license-image]][license-url][versions-image]: https://img.shields.io/pypi/pyversions/aiogqlc
[versions-url]: https://github.com/DoctorJohn/aiogqlc/blob/main/pyproject.toml
[pypi-image]: https://img.shields.io/pypi/v/aiogqlc
[pypi-url]: https://pypi.org/project/aiogqlc/
[downloads-image]: https://img.shields.io/pypi/dm/aiogqlc
[downloads-url]: https://pypi.org/project/aiogqlc/
[codecov-image]: https://codecov.io/gh/DoctorJohn/aiogqlc/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/DoctorJohn/aiogqlc
[license-image]: https://img.shields.io/pypi/l/aiogqlc
[license-url]: https://github.com/DoctorJohn/aiogqlc/blob/main/LICENSEA Python asynchronous/IO GraphQL client based on [aiohttp][aiohttp-url].
In addition to standard HTTP POST `queries` and `mutations` this client fully supports
the [GraphQL multipart form requests spec][multipart-specs-url] for file uploads
and the [graphql-ws subprotocol][graphql-ws-url] for WebSocket based `subscriptions`.**[Read the documentation][docs-url]**
## Installation
```sh
pip install aiogqlc
```## Basic usage
Check the [documentation][docs-url] for detailed and more advanced usage examples.
### Queries
```python
import asyncio
import aiohttp
from aiogqlc import GraphQLClientENDPOINT = "https://swapi-graphql.netlify.app/.netlify/functions/index"
document = """
query {
allFilms {
films {
title
}
}
}
"""async def main():
async with aiohttp.ClientSession() as session:
client = GraphQLClient(ENDPOINT, session=session)
response = await client.execute(document)
print(await response.json())if __name__ == "__main__":
asyncio.run(main())
```### Mutations
```python
import aiohttp
from aiogqlc import GraphQLClientdocument = """
mutation ($userId: ID!) {
deleteUser (id: $userId) {
id
}
}
"""variables = {
"userId": "42",
}async def main():
async with aiohttp.ClientSession() as session:
client = GraphQLClient("https://example.com/graphql/", session=session)
response = await client.execute(document, variables=variables)
print(await response.json())
```### File uploads
```python
import aiohttp
from aiogqlc import GraphQLClientdocument = """
mutation($file: Upload!) {
uploadFile(file: $file) {
size
}
}
"""variables = {
"file": open("test.txt", "rb")
}async def foo():
async with aiohttp.ClientSession() as session:
client = GraphQLClient("https://example.com/graphql/", session=session)
response = await client.execute(document, variables=variables)
print(await response.json())```
### Subscriptions
```python
import aiohttp
from aiogqlc import GraphQLClientdocument = """
subscription($postId: ID!) {
likeAdded(postId: $postId)
}
"""variables = {
"postId": "42"
}async def main():
async with aiohttp.ClientSession() as session:
client = GraphQLClient("https://example.com/graphql/", session=session)async with client.connect() as connection:
async for payload in connection.subscribe(document, variables=variables):
print(payload)
```## [Documentation][docs-url]
[Read the documentation][docs-url] to learn more about queries, mutations, subscriptions, file uploads and even authentication.
[aiohttp-url]: https://github.com/aio-libs/aiohttp
[multipart-specs-url]: https://github.com/jaydenseric/graphql-multipart-request-spec
[graphql-ws-url]: https://github.com/apollographql/subscriptions-transport-ws
[docs-url]: https://doctorjohn.github.io/aiogqlc/