Asynchronous/IO GraphQL client
A Python asynchronous/IO GraphQL client based on aiohttp.
In addition to standard HTTP POST queries and mutations this client fully supports
the GraphQL multipart form requests spec for file uploads
and the graphql-ws subprotocol for WebSocket based subscriptions.
Installation
pip install aiogqlc
Basic usage
Check the documentation for detailed and more advanced usage examples.
Queries
import asyncio
import aiohttp
from aiogqlc import GraphQLClient
endpoint = "https://swapi-graphql.netlify.app/graphql"
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
import aiohttp
from aiogqlc import GraphQLClient
document = """
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
import aiohttp
from aiogqlc import GraphQLClient
document = """
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
import aiohttp
from aiogqlc import GraphQLClient
document = """
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
Read the documentation to learn more about queries, mutations, subscriptions, file uploads and even authentication.
Metadata
Release files for aiogqlc 5.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiogqlc-5.4.0.tar.gz | 153.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiogqlc-5.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 161.1 kB
Release files / aiogqlc-5.4.0.tar.gz
| Download URL | aiogqlc-5.4.0.tar.gz |
|---|---|
| Size | 153.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71e0605e5bf2a57c371040b56f0dae0674fad28bda145e24d6d5562019cfd082
|
|
BLAKE2b-256 checksum How to use checksums |
59e7f54954d4a11bc58fa1be218e928f2afe27df983d5eaab50915ec605ba151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.3
|
Release files / aiogqlc-5.4.0-py3-none-any.whl
| Download URL | aiogqlc-5.4.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc0ac08f6c1af71b39518e3e3208069125081e2ab5b14cdf7b7e4611b3856cff
|
|
BLAKE2b-256 checksum How to use checksums |
3f4d0fa7496cc3a1f63c148239cf3f58df8aa2526141db6959a0ea2904fca5f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.3
|