Skip to main content

aiohttp based GraphQL client

Project description

Asynchronous/IO GraphQL client

Versions PyPI Downloads Codecov License

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.

Read the documentation

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogqlc-5.4.0.tar.gz (153.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogqlc-5.4.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file aiogqlc-5.4.0.tar.gz.

File metadata

  • Download URL: aiogqlc-5.4.0.tar.gz
  • Upload date:
  • Size: 153.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.3

File hashes

Hashes for aiogqlc-5.4.0.tar.gz
Algorithm Hash digest
SHA256 71e0605e5bf2a57c371040b56f0dae0674fad28bda145e24d6d5562019cfd082
MD5 93a438265bbd6949c84b79c47869fe1f
BLAKE2b-256 59e7f54954d4a11bc58fa1be218e928f2afe27df983d5eaab50915ec605ba151

See more details on using hashes here.

File details

Details for the file aiogqlc-5.4.0-py3-none-any.whl.

File metadata

  • Download URL: aiogqlc-5.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.3

File hashes

Hashes for aiogqlc-5.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc0ac08f6c1af71b39518e3e3208069125081e2ab5b14cdf7b7e4611b3856cff
MD5 437f35cc5fdff4cdbf45e2dd63754f6c
BLAKE2b-256 3f4d0fa7496cc3a1f63c148239cf3f58df8aa2526141db6959a0ea2904fca5f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page