Skip to main content

aiohttp based GraphQL client with file upload support

Project description

Asynchronous/IO GraphQL client

PyPI PyPI - License

A Python asynchronous/IO GraphQL client based on aiohttp that supports the GraphQL multipart form requests spec for file uploads.

Requirements

Installation

pip install aiogqlc

Usage

Executing simple queries

import asyncio
from aiogqlc import GraphQLClient


query = '''
    query {
        allFilms {
            title
        }
    }
'''

async def foo():
    client = GraphQLClient('https://swapi.graph.cool/')
    response = await client.execute(query)
    print(await response.json())

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(foo())

Adding authorization headers

from aiogqlc import GraphQLClient

headers = {
    'Authorization': 'Token <your-token-here>'
}

client = GraphQLClient('https://example.com/graphql/', headers=headers)

Single file upload

from aiogqlc import GraphQLClient

query = '''
    mutation($file: Upload!) {
        yourSingleUploadMutation(file: $file) {
            errors {
                field
                messages
            }
        }
    }
'''

variables = {
    'file': open('test.zip', 'rb'),
}

async def foo():
    client = GraphQLClient('https://example.com/graphql/')
    response = await client.execute(query, variables=variables)
    print(await response.json())

Multiple file upload

from aiogqlc import GraphQLClient

query = '''
    mutation($files: [Upload!]!) {
        yourMultiUploadMutation(files: $files) {
            errors {
                field
                messages
            }
        }
    }
'''

variables = {
    'files': [
        open('foo.zip', 'rb'),
        open('var.zip', 'rb'),
    ],
}

async def foo():
    client = GraphQLClient('https://example.com/graphql/')
    response = await client.execute(query, variables=variables)
    print(await response.json())

Project details


Download files

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

Files for aiogqlc, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size aiogqlc-1.0.3-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiogqlc-1.0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page