ObjectQL: A GraphQL server for Python

ObjectQL is a library for creating a GraphQL server with Python.

https://gitlab.com/kiwi-ninja/objectql/badges/master/coverage.svg https://gitlab.com/kiwi-ninja/objectql/badges/master/pipeline.svg

ObjectQL requires Python 3.5 or newer.


ObjectQL uses Python classes, methods and typehints to create the schemas and resolvers for a GraphQL engine.

With ObjectQL, the following Python class:

schema = ObjectQLSchema()

@schema.root
class Calculator:

  @schema.query
  def add(self, number_one: float, number_two: float) -> float:
      return number_1 + number_2

can be automatically mapped into a GraphQL schema that would look something like:

type Calculator {
    add(numberOne: Float!, numberTwo: Float!): Float!
}

and like any normal GraphQL server it can be queried:

executor = schema.executor()

executor.execute("
    query {
        add(numberOne: 4.3, numberTwo: 7.1)
    }
")

>>> {
    "add": 11.4
}

Getting Started

Install ObjectQL:

pip install objectql

Simple Example:

from objectql import ObjectQLSchema

schema = ObjectQLSchema()


@schema.root
class Math:

    @schema.query
    def square_number(self, number: int) -> int:
        return number * number


gql_query = '''
    query SquareNumberFive {
        fiveSquaredIs: squareNumber(number: 5)
    }
'''

result = schema.executor().execute(gql_query)

print(result.data)

…run in terminal:

$ python example.py
>>> {'fiveSquaredIs': 25}