Skip to main content

GraphQL Framework for Python

Project description

This is a forked version of graphene with support for subscriptions.

For executing a subscription, you can directly call the subscribe method on it. This method is async and must be awaited.

import asyncio
from datetime import datetime
from graphene import ObjectType, String, Schema, Field

# All schema require a query.
class Query(ObjectType):
    hello = String()

    def resolve_hello(root, info):
        return 'Hello, world!'

class Subscription(ObjectType):
    time_of_day = Field(String)

    async def subscribe_time_of_day(root, info):
        while True:
            yield { 'time_of_day':}
            await asyncio.sleep(1)

SCHEMA = Schema(query=Query, subscription=Subscription)

async def main(schema):

    subscription = 'subscription { timeOfDay }'
    result = await schema.subscribe(subscription)
    async for item in result:

The result is an async iterator which yields items in the same manner as a query.

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 jetblack-graphene, version 3.0b0
Filename, size File type Python version Upload date Hashes
Filename, size jetblack_graphene-3.0b0-py2.py3-none-any.whl (96.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size jetblack-graphene-3.0b0.tar.gz (31.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