asyncio + graphql = fast and simple api
Project description
asyncio - explicit concurrency to reduce race conditions
graphql - all you need and nothing more in one request +auto docs of your api
minimal http - unlike REST frameworks that are waste of time for /graphql endpoint
pluggable context - for auth, logging, etc
exception handling - at all levels, with default or custom handler
Usage:
pip install aiographql cat <<'END' >serve.py import asyncio, aiographql, graphene class User(graphene.ObjectType): id = graphene.ID(required=True) name = graphene.String() class Query(graphene.ObjectType): me = graphene.Field(User) async def resolve_me(self, info): await asyncio.sleep(1) # DB return User(id=42, name='John') schema = graphene.Schema(query=Query, mutation=None) aiographql.serve(schema) END UNIX_SOCK=/tmp/worker0 python3 serve.py curl --unix-socket /tmp/worker0 http:/ --data-binary '{"query": "{ me { id name } }", "variables": null}' # Result: # 1 second async await for DB and then: {"data":{"me":{"id":"42","name":"John"}}}
See more examples and tests about JWT auth, concurrent slow DB queries, etc.
Config:
import aiographql; help(aiographql.serve) serve(schema, get_context=None, unix_sock=None, exception_handler=None, enable_uvloop=True, run=True) Configure the stack and start serving requests
schema: graphene.Schema - GraphQL schema to serve
get_context: None or callable(headers: bytes, request: dict): mixed - callback to produce GraphQL context, for example auth
unix_sock: str - path to unix socket to listen for requests, defaults to env var UNIX_SOCK or '/tmp/worker0'
exception_handler: None or callable(loop, context: dict) - default or custom exception handler as defined here
enable_uvloop: bool - enable uvloop for top performance, unless you have a better loop
run: bool - if True, run the loop and the coroutine serving requests, else return this coroutine
return: coroutine or None - the coroutine serving requests, unless run=True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiographql-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5ed69f58055130f35bdf90ce830d6200e2ce360b8a10809573464ae4ae7bc37 |
|
MD5 | c1e3172e5b8bd6e849f4c519b470e018 |
|
BLAKE2b-256 | 3185e0243cabc20123fbed7d716eaa1503ccfb9c3359549cff08d439c0d2a797 |